ABH
ABH

Reputation: 119

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

Upvotes: 1

Views: 5408

Answers (1)

Ahmad Mageed
Ahmad Mageed

Reputation: 96477

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.

Upvotes: 3

Related Questions