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

How to obtain HighCharts series "id" from "series" elements?

本文关键字:系列 获取 HighCharts id 元素      更新时间:2023-09-26

我使用高图表.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

后来我需要遍历所有系列,我使用 cycle 做

// 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"?

给定id属性的位置,如下所示:

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

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

chart.series[x].options.id