Chartjs-Issue with customisation of Chart new.js for bar chart

0👍

I fixed this my adding below code in ChartNew.js

while (barWidth > 80) {
  config.barValueSpacing = config.barValueSpacing + 10;
  barWidth = (valueHop - Math.ceil(ctx.chartLineScale * config.scaleGridLineWidth) * 2 - (Math.ceil(ctx.chartSpaceScale * config.barValueSpacing) * 2) - (Math.ceil(ctx.chartSpaceScale * config.barDatasetSpacing) * nrOfBars - 1) - ((Math.ceil(ctx.chartLineScale * config.barStrokeWidth) / 2) * nrOfBars - 1)) / nrOfBars;
}

In above code 80 is max size that you want to set.
Put this code exactly at line number 3883, below line:

barWidth = (valueHop - Math.ceil(ctx.chartLineScale * config.scaleGridLineWidth) * 2 - (Math.ceil(ctx.chartSpaceScale * config.barValueSpacing) * 2) - (Math.ceil(ctx.chartSpaceScale * config.barDatasetSpacing) * nrOfBars - 1) - ((Math.ceil(ctx.chartLineScale * config.barStrokeWidth) / 2) * nrOfBars - 1)) / nrOfBars;

For more reference, put this code inside function:
var Bar = function(data, config, ctx) {}, below the line where barWidth is set.

Its working ace for me.

Leave a comment