Bar chart data labels not showing up for zero value
I am not able to show data label for bar chart if it has only one value i.e 0 in data set.My requirement is that I need to show data labels even if it has all zeroes or even one in such case
They are there, it's just that c3 has miscalculated their y offset pushing them all out of the main chart clip
If you can run through your data series and detect they're all going to be zero (after rendering the main chart), you can do this:
var seriesName = /*name of series concerned/*;
d3.selectAll(".c3-texts-"+seriesName+" > text").attr("dy", "-20px");
Undo it (return dy to 0px) if you then change the data to get a non-zero value in the series
@martingraham Any idea where in the source code the miscalculation is occurring?
You're right that the labels are "there", but when the values are all 0, the labels are positioned below the zero line (as they would be if there were negative values).
To fill in more details, this only occurs if all the values on the graph are 0. Changing the range of the Y axis (to be 0 to 1 for example, rather than 0 to 0) doesn't seem to help.
I would think that if I've explicitly said that the Y axis goes into the positive range (by specifying its maximum), then the labels for 0 values should go above the zero line.