如何从“系列”元素中获取HighCharts系列“id”?

时间:2014-12-15 20:23:45

标签: javascript highcharts

我使用highcharts.js并在创建系列时指定了id:

var series = [];
var key = "123";
var chartObject = {
    type: 'line',
    id: key,
    name: "NAME"
    data: [],
};

/// filling chartObject.data array
series.push(chartObject);
/// later this array of objects assigned as series property 
/// in HighCharts.Chart() configuration

后来我需要遍历所有系列,我使用循环

// chart is my object made elsewhere with chart = new Highcharts.Chart({...});
var cs = chart.series;

angular.forEach(chart.series, function (s) {
    // Here I want to know series ID to set visibility to true or false.
    s.setVisible(false);
    // debug
    console.log(s.name); // WORKS OK
    console.log(s.id);; // RETURNS UNDEFINED
});

如何从“系列”对象中获取“id”?

1 个答案:

答案 0 :(得分:2)

考虑到id属性的位置,如下所示:

series = {
    type: 'line',
    id: 'myid',
    name: 'my name',
    data: [],
}

你可以为任何给定的系列索引x获取它,如下所示:

chart.series[x].options.id