Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Highcharts dynamically add/change yAxis plotLines

I'm trying to make it possible for my users to add a max plotLine to a chart and have it change the background color of the chart if a plot goes above that line. I can't seem to get a method to update the plotlines. I've tried:

chart.yAxis[0].update({
    plotLines: [{
        id: 'limit-max',
        color: 'blue',
        dashStyle: 'LongDashDot',
        width: 1,
        value: 45000,
        zIndex: 0
    }]
});

but I get the error:

TypeError: a is undefined

...dBands,function(a){a.render()});n(this.series,function(a){a.isDirty=!0})},setCat...

highcharts.js (line 136)

like image 966
jbolanos Avatar asked May 21 '13 18:05

jbolanos


3 Answers

You can only destroy and create new plotLins, because update() function is not available.

like image 151
Sebastian Bochan Avatar answered Oct 26 '22 06:10

Sebastian Bochan


just add this code and then you can use the plotline.update method

    //Add support for update method
    Highcharts.PlotLineOrBand.prototype.update = function (newOptions){
        var plotBand = this;
        Highcharts.extend(plotBand.options, newOptions);
        if (plotBand.svgElem) {
            plotBand.svgElem.destroy();
            plotBand.svgElem = undefined;
            plotBand.render();
        }
    }
like image 31
Akram Kamal Qassas Avatar answered Oct 26 '22 05:10

Akram Kamal Qassas


Here's what worked for me http://jsfiddle.net/tx1kt0bj/2/

var plotBand = tempAxis.plotLinesAndBands[0];

$.extend(plotBand.options, {
    color: '#000',
    to: 10,
    from: 2
});
plotBand.svgElem.destroy();
plotBand.svgElem = undefined;
plotBand.render();
like image 1
Thomas Vo Avatar answered Oct 26 '22 06:10

Thomas Vo