highcharts-react icon indicating copy to clipboard operation
highcharts-react copied to clipboard

Graph changes unexpectly, and randomly

Open brunouber opened this issue 6 years ago • 2 comments

I've created a demo of the issue on code sandbox, https://codesandbox.io/s/goofy-violet-94007.

We load data of the series asynchronously, from different endpoints. So, we cannot be sure which series load first... We set the index field on each series to force a given order.

Everything work fine on the first render... But the graph changes randomly when a re-render happen.

You can test this behaviour on the sandbox.

We've found that everything works fine when we don't set the index field... but in this case we've no way to assure the order of the series match our expectation.

Version in use:

image

brunouber avatar Sep 28 '20 10:09 brunouber

Hello @brunouber,

Thank you for contacting us!

As you can find in the documentation:

A good practice is to keep all chart options in the state. When setState is called, the options are overwritten and only the new ones are passed to the chart.update method.

Meanwhile, in your demo, the series is defined as a different, outstanding state. To avoid the unexpected errors, like in your demo, it is recommended to update the chart options in the state.

Please analyze this demo: https://codesandbox.io/s/brave-meadow-ug8sj?file=/src/App.js

I did some refactoring and now the series is an array of objects which is attached to the main chart state options.

Basts avatar Sep 29 '20 08:09 Basts

@Basts Thank you for the quick reply. I've followed your advice, and it fixes the issue. Thank you very much.

brunouber avatar Sep 29 '20 09:09 brunouber