Chartjs-How do I horizontally center a line chart when their is a single X-Axis value?

0👍

See Chartjs linechart with only one point – how to center

You can add dummy labels to center your single point:

{
    type: 'line',
    data: {
        labels: ['', 'Jan', ''],
        datasets: [
            { borderColor: 'green', data: [null, 5, null], label: 'SET1' },
            { borderColor: 'red', data: [null, 7, null], label: 'SET2' },
            { borderColor: 'blue', data: [null, 3, null], label: 'SET3' }
        ]
    }
}

Or you can use the scatter chart type to manually specify the x coordinate of your points.

Leave a comment