Highcharts条件数据标签

时间:2015-09-07 00:15:56

标签: javascript highcharts

我想用条件格式标记系列数据,但它不适用于我。请帮我解决这个问题。我已经粘贴了我的基本数据系列代码,我想根据阈值进行标记,但我无法做到。如果我评论if条件,则标签显示整个系列。

$(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]
    }]
});
});

1 个答案:

答案 0 :(得分:2)

使用formatter option使用包含逻辑的回调并返回所需的格式。有关可在回调中使用的数据,请参阅文档链接。

将此format替换为formatter

formatter: function() {
    return this.y > 130 ? this.y + ' mm' : null;
}

这里是JSFiddle example