I'm having trouble updating the chart data. Inside the react app I have a useState hook where the chart data is stored. When the user clicks on a series, I want to hide all other series and show only the one he clicked on. Here is the code as I implemented it.
Code: Select all
const [chartOptions, setChartOptions] = React.useState<Highcharts.Options>({});
setChartOptions({
plotOptions: {
series: {
label: {
connectorAllowed: false
},
marker: {
enabled: true
},
cursor: 'pointer',
events: {
click() {
const { name } = this;
const lines = cloneDeep(chartPoints);
if (!historyEnabled) {
lines?.forEach((item) => {
if (item.type === 'line' && String(item.name) !== String(name)) {
item.visible = false;
} else {
console.log(name);
}
});
} else {
lines?.forEach((item) => {
if (item.type === 'line') {
item.visible = true;
}
});
}
historyEnabled = !historyEnabled;
if (lines) {
[color=#FF0000]// HERE IS THE PROBLEM. I FILTER THE DATA AND SET UP NEW SERIES, BUT THE TABLE IS NOT UPDATED[/color]
const newData = lines.filter((item) => item.visible);
setChartOptions({
series: newData
});
}
}
}
}
},
})