Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to modify bar width in Chartjs 2 bar charts

Can someone told me how to modify bar width in Chartjs 2 bar charts. There is nothing about it in the documentation.

https://github.com/nnnick/Chart.js/tree/v2.0-dev/docsI don't know what to do.

like image 277
VictorArcas Avatar asked Jul 02 '15 15:07

VictorArcas


2 Answers

For version 2.4.0 barThickness - Manually set width of each bar in pixels. If not set, the bars are sized automatically.

options = {
    scales: {
        xAxes: [{
            barThickness : 73
        }]
    }
}
like image 149
Mihail Lebedev Avatar answered Sep 21 '22 09:09

Mihail Lebedev


For me, trying 2.0 beta, what worked was to set the barPercentage on the xAxes scale option.

This is what I used:

var options = {
    data: chartData,
    type: "bar",
    options: {
        scales: {
            xAxes: [{ barPercentage: 0.5 }]
        }
    }
};
var chart = new Chart(chartCtx, options);
like image 26
py7133 Avatar answered Sep 21 '22 09:09

py7133