Show N / A in datalabels when value is null - Highcharts

I want to show "N / A" in the column chart when the data is zero. This is what I'm trying to do now: http://jsfiddle.net/90amxpc1/1/

dataLabels: {
                formatter: function () {
                    if (this.y == null) {
                        return "N/A";
                    }
                    else {
                        return this.y;
                    }
                }
}

But its not working. What I want to achieve seems to be an accepted answer to this question: Highcharts: return N / A instead of 0% in the data label or this fiddle: http://jsfiddle.net/v5vJR/3/

I tried changing it for a column chart, but it does not work.

+4
source share
1 answer

There is only other logic for the bar (inverted diagram) and column diagrams, an example for a column:

            formatter: function () {
                if (this.y == null) {
                    var chart = this.series.chart,
                        categoryWidth = chart.plotWidth / chart.xAxis[0].categories.length,
                        offset = (this.point.x) * categoryWidth + categoryWidth / 2,
                        text = chart.renderer.text('N/A', -999, -999).add();

                    text.attr({
                        x: chart.plotLeft + offset - text.getBBox().width / 2, //center label
                        y: chart.plotTop + chart.plotHeight - 8 // padding
                    });

                } else {
                    return this.y;
                }
            },

Live demo: http://jsfiddle.net/90amxpc1/4/

:
text, , .

+2

All Articles