Accepted answer

you can add new options, which are not available by default.but you need to edit chart.js

in chart.js add these lines of code step 1:

//boolean - whether barwidth should be fixed
        //number - pixel width of the bar

add these two line in defaultconfig of bar chart

step 2:

calculatebarwidth : function(datasetcount){

                        return options.barwidth;
                        //the padding between datasets is to the right of each bar, providing that there are more than 1 dataset
                        var basewidth = this.calculatebasewidth() - ((datasetcount - 1) * options.bardatasetspacing);
                            return (basewidth / datasetcount);

add this condition in calculatebarwidth function of barchart

now you can set barwidth in custom js file as option by setting


if you don't want to specify fixed barwidth, just change isfixedwidth:false


did you tried following options?

    //boolean - whether the scale should start at zero, or an order of magnitude down from the lowest value
    scalebeginatzero : true,

    //boolean - whether grid lines are shown across the chart
    scaleshowgridlines : true,

    //string - colour of the grid lines
    scalegridlinecolor : "rgba(0,0,0,.05)",

    //number - width of the grid lines
    scalegridlinewidth : 1,

    //boolean - whether to show horizontal lines (except x axis)
    scaleshowhorizontallines: true,

    //boolean - whether to show vertical lines (except y axis)
    scaleshowverticallines: true,

    //boolean - if there is a stroke on each bar
    barshowstroke : true,

    //number - pixel width of the bar stroke
    barstrokewidth : 2,

    //number - spacing between each of the x value sets
    barvaluespacing : 5,

    //number - spacing between data sets within x values
    bardatasetspacing : 1,

    //string - a legend template
    legendtemplate : "<ul class=\"<%=name.tolowercase()%>-legend\"><% for (var i=0; i<datasets.length; i++){%><li><span style=\"background-color:<%=datasets[i].fillcolor%>\"></span><%if(datasets[i].label){%><%=datasets[i].label%><%}%></li><%}%></ul>"



i did it by extending bar chart, and calculating barvaluespacing dynamically. i use angular chartjs

var max_bar_width = 50;{
            name: "baralt",
            draw: function(){
              var datasetsize = n // calculate ur dataset size here
              var barw = this.chart.width / datasetsize;
              if(barw > max_bar_width){
                this.options.barvaluespacing = math.floor((this.chart.width - (max_bar_width * datasetsize)) / datasetsize);
    , arguments);


its kinda late to answer this but hope this helps someone out there... play around with bardatasetspacing [ adds spacing after each bar ] and barvaluespacing [ adds spacing before each bar ] to be able to achieve your desired bar width.. example below when initiating your bar chart

... bardatasetspacing:10, barvaluespacing:30, ...

hope it helps..

Related Query

More Query from same tag