Search code examples
highchartsthreshold

Two different thresholds in HighCharts 3.0


With HighCharts 3.0, it is now possible to indicate to colors above and below one threshold. Like this example :

http://jsfiddle.net/highcharts/YWVHx/

Following code :

$(function () {
    $.getJSON('http://www.highcharts.com/samples/data/jsonp.php?filename=range.json&callback=?', function(data) {

        $('#container').highcharts({

            chart: {
                type: 'arearange'
            },

            title: {
                text: 'Temperature variation by day'
            },

            xAxis: {
                type: 'datetime'
            },

            yAxis: {
                title: {
                    text: null
                }
            },

            tooltip: {
                crosshairs: true,
                shared: true,
                valueSuffix: '°C'
            },

            legend: {
                enabled: false
            },

            series: [{
                name: 'Temperatures',
                data: data,
                color: '#FF0000',
                negativeColor: '#0088FF'
            }]

        });
    });

});

Is it possible to have another threshold with a third color, like this for example :

Chart with a double threshold

Thanks in advance for your help.


Solution

  • A feature to solve this without "hacks" was added in Highcharts 4.1.0 (February 2015), called zones (API). The given problem can be solved like this, using zones:

    plotOptions: {
        series: {
            zones: [{
                value: 0, // Values up to 0 (not including) ...
                color: 'blue' // ... have the color blue
            },{
                value: 10, // Values up to 10 (not including) ...
                color: 'orange' // ... have the color orange
            },{
                color: 'red' // Values from 10 (including) and up have the color red
            }]
        }
    }
    

    See this JSFiddle demonstration of how it looks.