高图条件数据标签
问题描述:
我想用条件格式标记系列数据,但是它对我不起作用.请帮助我解决问题.我已经为基本数据系列粘贴了代码,我想根据阈值对其进行标记,但是我无法做到这一点.如果我评论if条件,那么整个系列的标签都会显示出来.
I would like to label the series data with conditional formatting but its not working for me. Please help me fixing the issue. I have pasted my code for basic data series which i would like to label based on the threshold but i am unable to do that. if i comment the if condition then the label shows up for the entire series.
$(function () {
$('#container').highcharts({
xAxis: {
categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
},
plotOptions: {
series: {
dataLabels: {
enabled: true,
if(this.y: >130){
format: '{y} mm'
}
}
}
},
series: [{
data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4]
}]
});
});
答
使用 formatter
选项使用包含您的逻辑并返回所需格式的回调.请参阅文档链接,以获取可在回调中使用的数据.
Use the formatter
option to use a callback that contains your logic and returns your desired format. Refer to the documentation link for data available for use within the callback.
用formatter
替换format
:
formatter: function() {
return this.y > 130 ? this.y + ' mm' : null;
}
这是一个 JSFiddle示例.