TW_KuanLun
TW_KuanLun

Reputation: 87

How to trigger legend click event on outside when using Highchart and no using JQuery

I use React, so I don’t want to import JQuery to increase the bundle size,

I need to trigger the legend click event of multiple charts at the same time when the button is clicked outside the Highchart

Is there any way to trigger the legend click event using chart object like below

let chart = Highcharts.chart('id', { ...options });

chart.legend.allItems[0].legendItem.click(); //not work

Upvotes: 1

Views: 914

Answers (1)

Sebastian Wędzel
Sebastian Wędzel

Reputation: 11633

Please check this approach how to toggle series visibility on a custom button using the Highcharts-react wrapper.

Demo: https://stackblitz.com/edit/react-uyubam?file=index.js

  const updateSeries = () => {
    visibility = !visibility;
    setChartOptions({
      series: [{ visible: visibility }]
    });
    setChartOptions1({
      series: [{ visible: visibility }]
    });
  };

API: https://api.highcharts.com/highcharts/series.line.visible

Upvotes: 3

Related Questions