Вы можете передать event
и контекст this
в обработчик функции щелчка метки.
label: {
onclick: function (event) {
func(event,this);
this.renderer.label(
'You just clicked a custom menu item',
100,
100
)
},
text: 'Show label'
}
function func(event,context){
console.log("chart id => ",context.renderTo.getAttribute('id'));
}
Обновленный код
Highcharts.chart('container', {
title: {
text: 'Solar Employment Growth by Sector, 2010-2016'
},
subtitle: {
text: 'Source: thesolarfoundation.com'
},
yAxis: {
title: {
text: 'Number of Employees'
}
},
legend: {
layout: 'vertical',
align: 'right',
verticalAlign: 'middle'
},
plotOptions: {
series: {
label: {
connectorAllowed: false
},
pointStart: 2010
}
},
exporting: {
menuItemDefinitions: {
// Custom definition
label: {
onclick: function (event) {
func(event,this);
this.renderer.label(
'You just clicked a custom menu item',
100,
100
)
},
text: 'Show label'
}
},
buttons: {
contextButton: {
menuItems: ['downloadPNG', 'downloadSVG', 'separator', 'label']
}
}
},
series: [{
name: 'Other',
data: [12908, 5948, 8105, 11248, 8989, 11816, 18274, 18111]
}],
responsive: {
rules: [{
condition: {
maxWidth: 500
},
chartOptions: {
legend: {
layout: 'horizontal',
align: 'center',
verticalAlign: 'bottom'
}
}
}]
}
});
function func(event,context){
console.log("chart id => ",context.renderTo.getAttribute('id'));
}
Рабочая демонстрация jsFiddle - https://jsfiddle.net/sc0Lg4uh/1/
Проверьте console.log для идентификатора контейнера.