How can I reset the styles given to series in Highcharts?

前端 未结 4 1172
执笔经年
执笔经年 2021-01-18 07:31

I am using Highcharts to render some graphs to my website. Sometimes, I need to remove all series from the chart and add some new series to the chart, because I requested so

4条回答
  •  旧时难觅i
    2021-01-18 07:54

    I found the solution in a pull request on GitHub (https://github.com/highslide-software/highcharts.com/pull/203).

    You just need to reset Highcharts color counter after deleting the series. There is also a counter for the symbols.

    UPDATE: From version 4.0.3 and above the name of the counters has changed:

    var chart = $('#container').highcharts();
    while(chart.series.length) {
        chart.series[0].remove();
    }
    
    chart.colorCounter = 0;
    chart.symbolCounter = 0;
    
    chart.addSeries({
         data: [144.0, 176.0, 29.9, 71.5, 106.4, 129.2, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4]
    });
    chart.addSeries({
        data: [129.2, 106.4, 135.6, 95.6, 54.4, 148.5, 144.0, 176.0, 29.9, 71.5, 216.4, 194.1]
    });
    chart.addSeries({
        data: [106.4, 129.2, 135.6, 148.5, 144.0, 176.0, 29.9, 71.5, 194.1, 95.6, 54.4, 216.4]
    });
    

    Live example: http://jsfiddle.net/juuQs/18/

    (Prior to version 4.0.3 you must use chart.counters.color = 0 and chart.counters.symbol = 0)

提交回复
热议问题