Highcharts conditional data label

自作多情 提交于 2019-12-11 21:29:57

问题


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

回答1:


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.

Replace format with this formatter:

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

Here's a JSFiddle example.



来源:https://stackoverflow.com/questions/32429564/highcharts-conditional-data-label

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!