当值为 null 时,在数据标签中显示 N/A - Highcharts
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: Returning N/A value instead of 0% in data label
或者这个 fiddle: 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
变量以在隐藏系列或放大图表时删除该文本。
当数据为空时,我想在柱形图中显示 "N/A"。 这就是我目前正在尝试做的事情: http://jsfiddle.net/90amxpc1/1/
dataLabels: {
formatter: function () {
if (this.y == null) {
return "N/A";
}
else {
return this.y;
}
}
}
但是,它不起作用。我想要实现的是类似于这个问题的公认答案: Highcharts: Returning N/A value instead of 0% in data label 或者这个 fiddle: 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
变量以在隐藏系列或放大图表时删除该文本。