Chartjs-How does one reproduce this plot in JavaScript?

2👍

Managed to plot it using Plotly.js. If there is a more efficient way, would love to see it. Thanks.

        const data = createLabels(g);
        console.log(data);

        var layout = {
            showlegend: false,
            autosize: true,
            xaxis: {
                showticklabels: false,
                showline: false,
                zeroline: false,
                showgrid: false
            },
            yaxis: {
                showticklabels: false,
                showline: false,
                zeroline: false,
                showgrid: false
            }
        };

        Plotly.newPlot('div1', data, layout, { scrollZoom: true });

        function createLabels(g) {
            var t = -10;
            var c = -10;
            var dat = [];
            for (c = -10; c < 10; c++) {
                var x = [];
                var y = [];
                for (t = -10; t < 10; t = t + 0.1) {
                    var f = g(t) + c;
                    var u1 = 2 * t * f * f / (t ** 2 + f ** 2);
                    var u2 = 2 * t * t * f / (t ** 2 + f ** 2);
                    x.push(u1);
                    y.push(u2);
                };
                dat.push({ x: x, y: y })
            }
            return dat;
        }

        function g(u) {
            return -Math.exp(u) * u;
        }

Leave a comment