The project includes a Line chart with a legend that are initialized in separate containers. Both components are created using a createFromConfig method.
<div ref="chartdiv" />
<div ref="legenddiv" />
My goal is to store toggled legend items as users switch between multiple tabs on the page. When users return to the tab with the chart, I want to programmatically toggle back these items.
The algorithm for achieving this involves:
- Storing toggled items
- Toggling previously toggled items when the chart is initiated by showing/hiding series, not legend items.
I have successfully stored labels by adding a click handler to legend items.
chart.value.legend.itemContainers.template.events.on('hit', (ev) => {
toggledItems.push(ev.target.dataItem.name)
})
However, I am facing challenges with hiding previously toggled legend items. I have experimented with 'inited', 'hidden', 'shown' events as suggested in this question on stack overflow, but have not been successful.
// No reaction here ☹️
chart.value.series.template.events.on('hidden', () => {
console.log('I am hidden')
})
I would appreciate guidance on how to proceed in the right direction.