How to get series's id in Highcharts / Highstock

纵饮孤独 提交于 2019-12-09 12:50:27

问题


How to get Series's id? In the API there is only name and data etc. But don't have id. How could I get id from series?

I'm using the following way to loop all series in chart.

$(chart.series).each(function(i, serie){

    // Want to get serie's id

});

EDIT:

I found i can get id using the follow way. I'm not sure is it the right way?

 $(chart.series).each(function(i, serie){
        console.log(serie.options.id);

 });

回答1:


If you know the id of series already you can get a reference to the series by chart.get(ID)

If you want to loop through all the series and list all the IDs of series, do this:

 $(chart.series).each(function(i, serie){console.log(serie.options.id)})

FIddle : http://jsfiddle.net/NaK9D/2/




回答2:


From the documentation:

Another way to reference the series programmatically is by id. Add an id in the series configuration options, and get the series object by chart.get(id).

Looks like you can do:

$(chart.series).each(function(i, serie){
  this.get(id);
});


来源:https://stackoverflow.com/questions/16472331/how-to-get-seriess-id-in-highcharts-highstock

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!