Hi I have just started working with Highstock's javascript charts and was trying to figure out a way of adding and removing chart items dynamically. I am already able to add the chart series dynamically and have given them unique names, as well as ID values but I'm not sure these are sticking. I was wondering whether or not there is a way to dynamically remove series without knowing their index in the series array?
Thank you in advance, Conor
Hi I have just started working with Highstock's javascript charts and was trying to figure out a way of adding and removing chart items dynamically. I am already able to add the chart series dynamically and have given them unique names, as well as ID values but I'm not sure these are sticking. I was wondering whether or not there is a way to dynamically remove series without knowing their index in the series array?
Thank you in advance, Conor
Share Improve this question asked Aug 26, 2011 at 12:21 Bob-obBob-ob 1,6184 gold badges20 silver badges35 bronze badges2 Answers
Reset to default 6I also had trouble getting this to work, but found out it is possible if you set the id manually before you add it to the chart, then use chart.get() to retrieve the series.
newSeries.id = myID;
chart.addSeries(newSeries);
You can then later call:
chart.get(myID).remove()
I'm using this code to dynamically remove all series from a chart:
for(i=0;i<chart.series.length;i++){
chart.series[i].remove();
}
Worth noting that jQuerys $.each() didn't work, but the "for" loop did.