[Chartjs]-Chart.js xAxis linear scale : strange behavior

9👍

You’re not providing the data in correct format for the scatter line plot.

The correct format to provide the data is described by the following example from Chart.js Docs.

var scatterChart = new Chart(ctx/* your canvas context*/, {
 type: 'line',
    data: {
        datasets: [{
            label: 'Scatter Dataset',
            data: [{
                x: -10,
                y: 0
            }, {
                x: 0,
                y: 10
            }, {
                x: 10,
                y: 5
            }]
        }]
    },
    options: {
        scales: {
            xAxes: [{
                type: 'linear',
                position: 'bottom'
            }]
        }
    }
});

source

I think the x and y should be separable into different arrays, but you can always do a combination step and combine them into objects.

Leave a comment