Two different thresholds in HighCharts 3.0
Asked Answered
T

4

6

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.

Tartaric answered 4/6, 2013 at 20:28 Comment(0)
B
8

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.

Burge answered 14/1, 2016 at 23:36 Comment(1)
Great solution!, I was doing the multiple series approach prior.Reconnoiter
I
9

It actually is possible if you don't mind plotting the data twice.

    $('#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',
            threshold : 0,
            data: data,
            color: 'orange',
            negativeColor: 'blue'
        },
        {
            name: 'Temperatures',
            threshold : 10,
            data: data,
            color: 'red',
            negativeColor: 'transparent'
        }]
    });
});

http://jsfiddle.net/YWVHx/97/

Impudent answered 2/1, 2014 at 16:4 Comment(1)
@Ronald van - This was exactly I was looking for ! Great solution.Decapolis
B
8

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.

Burge answered 14/1, 2016 at 23:36 Comment(1)
Great solution!, I was doing the multiple series approach prior.Reconnoiter
B
1

Unfortunately this option is not possible, but you can request your suggestion in http://highcharts.uservoice.com and vote for it.

Baryon answered 5/6, 2013 at 9:9 Comment(3)
Thanks for your help, the suggestion is now posted and voted !Tartaric
@Tartaric Can you give us the link to your post, so I can upvote it too, please?Haemophilic
Here it is ! highcharts.uservoice.com/forums/55896-general/suggestions/…Tartaric
J
0

By the way, I can try use a plotLine, like this:

 yAxis: {
                title: {
                    text: 'My Chart'
                },
                plotLines: [{
                    id: 'limit-min',
                    dashStyle: 'ShortDash',
                    width: 2,
                    value: 80,
                    zIndex: 0,
                    label : {
                        text : '80% limit'
                    }
                }, {
                    id: 'limit-max',
                    color: '#008000',
                    dashStyle: 'ShortDash',
                    width: 2,
                    value: 90,
                    zIndex: 0,
                    label : {
                        text : '90% limit'
                    }
                }]
            },
Jereme answered 26/8, 2013 at 20:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.