I use Highcharts to display some graphs on my site. Sometimes I need to remove all series from the chart and add some new series to the chart because I requested some new data through ajax.
I am currently doing this:
var chart = $('#container').highcharts(); while(chart.series.length) { chart.series[0].remove(); } 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] });
You can see it in this violin .
But my problem is that the new series gets completely different colors from the first.
I can't just replace the data because the number of episodes is likely to change, so I need to delete all episodes and add new ones.
How can I archive a new series in a style similar to replaced? (In my violin, the new series should have lightblue, darkblue and some third color.)
Test cases
I created some test cases to clarify the problem that I am facing. The top chart is how it should look, and the bottom chart is how it really looks. I want them to be the same!
The solution should work with all of these cases!