How to get series's id in Highcharts / Highsto

2020-05-27 11:11发布

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);

 });

2条回答
我只想做你的唯一
2楼-- · 2020-05-27 11:48

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/

查看更多
成全新的幸福
3楼-- · 2020-05-27 12:08

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);
});
查看更多
登录 后发表回答