Reputation: 577
I need to access the chart (echarts 5.0.0) on which the tooltip ist shown from inside the tooltip formatter function. How can I access it?
let chartOption = {
//... all the other stuff
tooltip: {
//...
formatter: function (params, ticket, callback) {
//how to access chart when formatter function is called?
}
},
//... more stuff
};
let chart = echarts.init(document.getElementById("myChart"));
chart.setOption(chartOption);
Upvotes: 0
Views: 1829
Reputation: 7310
let chartOption = {
//... all the other stuff
tooltip: {
//...
formatter: function (params, ticket, callback) {
chart.xxx
}
},
//... more stuff
};
let chart = echarts.init(document.getElementById("myChart"));
chart.setOption(chartOption);
But I'm not sure what you want to do with the chart instance because in most cases you don't have to.
Upvotes: 0
Reputation: 577
I've solved this by getting the charts id from mouse position:
let elements = document.querySelectorAll( ":hover" );
let chartId = elements.item(elements.length -1).parentElement.parentElement.id;
let chart = charts[chartId];
where "charts" holds all the chart instances on the page with the id of the div as key.
Upvotes: 0