[Chartjs]-Chart.js line chart with correctly spaced x labels

3๐Ÿ‘

โœ…

As per Chart.js xAxis linear scale : strange behavior you need a linear x-axis with data supplied as x,y pairs.

So, it needs to be:

var ctx = document.getElementById('chartJSContainer').getContext('2d');
var scatterChart = new Chart(ctx, {
            type: 'line',
            data: {
                datasets: [{
                    label: 'Linear Dataset',
                    data: [{ x: 0, y: 1}
                          ,{x: 1, y: 2 }
                          ,{ x: 10, y: 1} ]
                          }]
                  },
            options: {
                scales: {
                    xAxes: [{
                        type: 'linear'
                        ,position: 'bottom'
                    }]
                }
            }
        });

Leave a comment