Search code examples
reactjsmaterial-uireact-chartjs

How can I keep the data after hiding it?


I have three graphics using react-chartjs-2, which are added certain values ​​using a modal.

The problem that happens to me is that I have a button that hides the graphics, but when I hide it and display them again the values ​​that are in the graphics are deleted and I don't know how to recover it.

Someone knows how to keep the data, here is the code.

code in stackblitz


Solution

  • File chart.js line 39, dataset.data = props.entries; changes props.entries to []. So we have to generate a copy to entries.

    So, add .slice() to file paper.js line 39.

    <Chart entries={entries.slice()} />