I've followed the hint in a previous answer to write a code line to get the HighCharts series by means of their id. Unfortunately, I was unable to do it. Consider the following toy example (on Jfiddle):
$(function () {
var cseries=[{
id: 'Tokyo',
name: 'Tokyo',
data: [7.0, 6.9, 9.5, 14.5, 18.2, 21.5, 25.2, 26.5, 23.3, 18.3, 13.9, 9.6]
}, {
id: 'New York',
name: 'New York',
data: [-0.2, 0.8, 5.7, 11.3, 17.0, 22.0, 24.8, 24.1, 20.1, 14.1, 8.6, 2.5]
}];
$('#container').highcharts({
series: cseries
});
var chart=$('#container').highcharts();
alert(chart.get('Tokyo').id);
});
When I cut the last line, the script goes well. When I don't cut the last line, the alert returns undefined. Why?
You are not closing enough brackets on the alert:
alert(chart.get('Tokyo');
should be:
alert(chart.get('Tokyo'));
And I think you would be better off doing a console.log(chart.get('Tokyo')); and see the output in the browser console, since it outputs an object which cannot be displayed in an alert.
Update based on post edit:
chart.get('Tokyo') does not have an id property
To get the series id, try console.log(chart.get('Tokyo').userOptions.id);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With