问题
I've been using the following code to set dataLabels for bar charts in Highcharts...
plotOptions: {
bar: {
dataLabels: {
enabled: true,
formatter: function() {
if (this.y==null) {
return '<i>(Suppressed)</i>';
} else {
return '';
}
}
}
}
}
Basically, I want to be able to show the user when a value has been hidden for privacy reasons.
In previous versions of Highcharts, the label would show up for the null values as I desired. In version 3.0.8, I do not get any dataLabels for the null vales.
Is there a workaround or fix for this?
回答1:
Possibly bug, reported here https://github.com/highslide-software/highcharts.com/issues/2899
Workaround: use renderer http://api.highcharts.com/highcharts#Renderer.text
回答2:
As Sebastian points out, this is in fact a bug. However, there is an easy fix... In highcharts.src.js, simply change the call to the pick function for getting plotX and plotY in Series.prototype.alignDataLabel (lines 16132 and 16133) to:
plotX = pick(point.plotX, 0),
plotY = pick(point.plotY, 0),
rather than
plotX = pick(point.plotX, -999),
plotY = pick(point.plotY, -999),
Hope this ends up being helpful to somebody...
来源:https://stackoverflow.com/questions/22963501/datalabels-for-bar-chart-in-highcharts-not-displaying-for-null-values-in-3-0-8