Skip to content

Failure on updating options and data at the same time #9

@ace-han

Description

@ace-han

The issue occurs after upgrade chart.js to 3.0-beta.11.

As I debugged, I located the issue is that a pull merged in 3.0-beta.11 chartjs/Chart.js#8374. This pull makes options gets updated depending on prev status data (old data)

An obvious bug in my case is that options with multiple y-axes toggling functionality failure.

Because old data(datasets) say toggling single axis( y ) to y-axes( y1, y2, ... ) had been assigned to y, net yet assigned to y1, y2, ..., but updating options depends on data (old data)

The problem code lies as below

chartInstance.current.options = options;
chartInstance.current.data = data;

We just need to switch these two lines will fix this issue

// $HOME/src/ReactChart.tsx
// other stuff...

  useEffect(() => {
    chartInstance.current.data = data;
    chartInstance.current.options = options;

    chartInstance.current.update(updateMode);
  }, [data, options]);

// other stuff... 

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions