Accepted answer

You can achieve this using Chart.js plugins. They let you handle specific events triggered during the chart creation (beforeInit, afterUpdate, afterDraw ...) and are also easy to implement :

    afterUpdate: function(chart) {
        // This will be triggered after every update of the chart

Now you just have to loop through your dataset data model (the property used to draw charts) and add the offset you want :

    afterUpdate: function(chart) {
        // We get the dataset and set the offset here
        var dataset =[0];
        var offset = 20;

        // For every data in the dataset ...
        for (var i = 0; i < dataset._meta[0].data.length; i++) {
            // We get the model linked to this data
            var model = dataset._meta[0].data[i]._model;

            // And add the offset to the `x` property
            model.x += offset;

            // .. and also to these two properties
            // to make the bezier curve fits the new graph
            model.controlPointNextX += offset;
            model.controlPointPreviousX += offset;

You can see your example working on this jsFiddle and here is its result :

enter image description here


Leading on from the answer given by 'tektiv' I needed a similar solution but one that works for RESPONSIVE CHARTS.

So instead of using fixed measurements for the given offset shown in tektiv's plugin, we first count the number of objects in the dataset array. We then divide the chart.width by the number of objects in the array to give us equal segments, then in order to define the half way point between each grid line, we divide that sum by a factor of 2.

Note 1: You could also replace the factor of 2 to a variable so the user could chose the portion of offset needed.

Note 2: I've placed the plugin code within the chart script given I don't want this as a global affect by registering a global plugin.

Note 3: This is second re-edit of my solution given the plugin code I partially copied from the answer given by 'tektiv' above was only firing successfully for the first time, but then when re-loading a new instance of the chart I experienced some null errors on the dataset._meta (worth also seeing answer here on this particular topic as this helped me fix and finalize my answer: Dataset._meta[0].dataset is null in ChartJS Code example:


    var myChart;

    function drawChart() {

        var ctx = document.getElementById('myChart').getContext('2d');
        ctx.innerHTML = '';

        if (myChart != null) {

        var datasetArray = [5, 10.5, 18.2, 33.9, 121.2, 184.9, 179.9, 196.1, 158.3, 166.3, 66.4, 20.6, null];

        myChart = new Chart(ctx, {
            type: 'line',
            data: {
                labels: ["JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JUL", "AUG", "SEP", "OCT", "NOV", "DEC", ""],
                datasets: [{
                    data: datasetArray,
                    borderWidth: 2,
                    borderColor: "#f37029",
                    pointBorderColor: "#f37029",
                    pointBackgroundColor: "#f37029",
                    pointHitRadius: 10,
                    spanGaps: false,
            plugins: [{
                afterUpdate: function (chart, options) {
                    var dataset =[0];

                    // Get the number of objects in the dataset array.
                    var noDataPoints = datasetArray.length;

                    //alert(noDataPoints); // testing only, you'll notice that this 
                    // alert would fire each time the responsive chart is resized.
                    var xOffset = (chart.width / noDataPoints) / 2;

                    for (var i = 0; i <; i++) {
                        for (var key in dataset._meta) {
                            var model = dataset._meta[key].data[i]._model;
                            model.x += xOffset;
                            model.controlPointNextX += xOffset;
                            model.controlPointPreviousX += xOffset;
            options: {
                scales: {
                    xAxes: [{
                        gridLines: {
                            offsetGridLines: false,
                            display: true,
                        ticks: {
                            fontSize: 8,
                            maxRotation: 0
                    yAxes: [{
                        gridLines: {
                            display: true
                        ticks: {
                            beginAtZero: true,
                legend: {
                    display: false
                responsive: true,
                maintainAspectRatio: true


First screenshot below shows the responsive chart stretched to a wide screen view:

wide screen

Second screenshot shows the responsive chart resized to a smaller and more conventional window size:

narrow screen


Check out - .

In chapter "Common Configuration",there is a Boolean attribute offset. Default value is false (except in case of bar chart)

If true, extra space is added to the both edges and the axis is scaled to fit into the chart area. This is set to true in the bar chart by default.

So you can just set it to true, and it should work.

Related Query

More Query from same tag