[英]Highcharts - How to force dataLabels to show labels when overlapping the content
[英]Show N/A in datalabels, when value is null - Highcharts
當數據為空時,我想在柱形圖中顯示“N / A”。 這就是我目前正在嘗試做的事: http : //jsfiddle.net/90amxpc1/1/
dataLabels: {
formatter: function () {
if (this.y == null) {
return "N/A";
}
else {
return this.y;
}
}
}
但是,它不起作用。 我想要實現的是類似於此問題的接受答案: Highcharts:在數據標簽或這個小提琴中返回N / A值而不是0% : http : //jsfiddle.net/v5vJR/3/
我嘗試為柱形圖修改它,但它沒有用。
條形圖(倒圖表)和柱形圖只有不同的邏輯,列的示例如下:
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;
}
},
現場演示: http : //jsfiddle.net/90amxpc1/4/
注意:
您可能希望存儲text
變量以在隱藏系列或放大圖表時刪除該文本。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.