chartjs / Chart.js

Simple HTML5 Charts using the <canvas> tag
https://www.chartjs.org/
MIT License
64.37k stars 11.89k forks source link

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

Open junaid-md opened 2 years ago

junaid-md commented 2 years ago

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

alinesouzadev commented 2 years ago

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

stockiNail commented 2 years ago

@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.