只有当dataLabels的值不是0时,我才想显示它。下面提到不想在UI charts.ts代码上显示0:
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,
},
},
},
},发布于 2022-09-06 11:14:48
使用格式函数
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,
},
},
},
},发布于 2022-09-06 13:23:42
数据标签需要使用formatter函数。例如:
dataLabels: {
...,
formatter: function() {
return this.y || '';
}
}现场演示: http://jsfiddle.net/BlackLabel/w82kr9fx/
API参考: https://api.highcharts.com/highcharts/series.bar.dataLabels.formatter
https://stackoverflow.com/questions/73620953
复制相似问题