如何格式化角度高图表中的数据标签



我只想在dataLabels的值不为0时显示它。并且不想在UI上显示0charts.ts代码如下所述:

plotOptions: {
series: {
states: {
inactive: {
opacity: 1,
},
},
dataLabels: {
enabled: true,
inside: true,
format: '{y}',
showInLegend: false,
},
stacking: 'normal',
},
bar: {
stacking: 'normal',
borderWidth: 0,
states: {
hover: {
enabled: false,
},
},
},
},

使用格式函数

plotOptions: {
series: {
states: {
inactive: {
opacity: 1,
},
},
dataLabels: {
enabled: true,
inside: true,
format: function(){
return (this.y != 0) ? this.y : "";
},
showInLegend: false,
},
stacking: 'normal',
},

bar: {
stacking: 'normal',
borderWidth: 0,
states: {
hover: {
enabled: false,
},
},
},
},

数据标签需要使用formatter函数。例如:

dataLabels: {
...,
formatter: function() {
return this.y || '';
}
}

现场演示:http://jsfiddle.net/BlackLabel/w82kr9fx/

API参考:https://api.highcharts.com/highcharts/series.bar.dataLabels.formatter

最新更新