Chartjs-Is it possible to update the width of a chart in chart.js?

1👍

Instead of changing the barFill.chart.canvas.width. change barFill.scale.width.

function updateChart(barData) {
    angular.forEach(oldData, function () {
        barFill.removeData();
    });
    oldData = barData;

    angular.forEach(barData, function (newBar, i) {
        barFill.addData([newBar], labels[i]);
    });

    barFill.scale.width = getWidth(barData);
    barFill.resize().update();
}

It works even without the call to update() by the way, but I just kept it because it is the right way as per the documentation.

I would recommend resizing the container instead of the canvas element btw.


Fiddle – http://jsfiddle.net/ja8cxybf/

Leave a comment