简体   繁体   中英

Highcharts conditional data label

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

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM