Chart.js icon indicating copy to clipboard operation
Chart.js copied to clipboard

chartjs: hide x-axis labels for which the dataset is all zeros in stacked bar chart

Open junaid-md opened this issue 3 years ago • 2 comments

I am trying to hide the dates below where the the dataset is all zero's for a particular label. Tried it with different things but unable to get my mind through it. Can anyone help? From the screenshot I want just to display the Wed, Fri and Monday in the chart and remove the rest which have all zeros.

image

junaid-md avatar May 11 '22 13:05 junaid-md

I've made it by adding in options.plugins.datalabels: datalabels: { display: function (context) { return context.dataIndex === 0; } }

alinesouzadev avatar Jun 01 '22 08:06 alinesouzadev

@junaid-md maybe I'm wrong but this could be a topic for CHART.JS project https://github.com/chartjs/Chart.js and not datalabels.

If I understood well your use case, you would like to hide the ticks on time axis when the value is 0.

You could use the ticks callback.

stockiNail avatar Jun 11 '22 09:06 stockiNail