admin管理员组

文章数量:1402837

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 badges
Add a ment  | 

2 Answers 2

Reset to default 6

I 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.

本文标签: javascriptRemove Highstock series with specific IDStack Overflow