Home Forums Chart Support How to sync multiple charts if charts are rendered with a condition

How to sync multiple charts if charts are rendered with a condition

Viewing 2 posts - 1 through 2 (of 2 total)
  • #60329

    https://stackblitz.com/edit/canvasjs-react-sync-zooming-panning-multiple-ch-7wzdt3ay?file=src%2FApp.js

    if you switch dashboard modes ou will see that the sync zoom no longer work

    #60332

    @scompliance,

    Zooming across charts is not working after switching the dashboard as you are resetting the chart-references on switching the charts. Instead setting the selectedDashboard only if the value has changed & adding chart-references only once should work fine for you. Please find the updated code-snippet below.

    Change selectedDashboard only if the value has changed.

    const handleDashboardChange = (event) => {
      if (event.target.value !== selectedDashboard) {
        setSelectedDashboard(event.target.value);
      }
    };

    Add chart-ref only once.

    <CanvasJSChart
      key={index}
      options={options}
      onRef={(ref) => {
        if (ref && !chartsRef.current.includes(ref)) {
          chartsRef.current.push(ref);
        }
      }}
    />

    Please take a look at this updated Stackblitz for working example.


    Vishwas R
    Team CanvasJS

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.