Chart.js Bar Chart: How to remove whitespace between columns in v2.3?

I am trying to remove the gap between the bars of the bar charts, but although I see this solution in many places, it does not work for me. It is also not mentioned in the Chart.js docs, so it is odd. Can someone tell me how to specify it?

var options = { barValueSpacing : 1, // doesn't work; find another way barDatasetSpacing : 1, // doesn't work; find another way legend: { display: false // Hides annoying dataset label }, tooltips: { callbacks: { label: function(tooltipItem) { return tooltipItem.yLabel; } } } }; var ctx = document.getElementById("canvasX").getContext("2d"); var myBarChart = new Chart(ctx, { type: 'bar', data: data, options: options }); 
+5
source share
1 answer

You need to set barPercentage and categoryPercentage to 1.0 on a scale along the x axis. Add this to your options object:

 var options = { ... scales: { xAxes: [{ categoryPercentage: 1.0, barPercentage: 1.0 }] } }; 

See http://www.chartjs.org/docs/#bar-chart-chart-options

+13
source

Source: https://habr.com/ru/post/1257741/


All Articles