๐:0
The problem is that you invoke update()
on the chartData
object but not on the chart instance. The chartData
object does not have an update()
function.
How to get a reference to the Chart.js instance is explained here.
Below code fragments illustrate what needs to be changed in your code to solve your problem.
constructor() {
...
this.chartReference = React.createRef();
}
componentDidMount() {
this.chart = this.chartReference.current.chartInstance;
...
}
addData(chart) {
...
this.chart.update(); // instead of chart.update();
}
removeData(chart) {
...
this.chart.update(); // instead of chart.update();
}
render() {
return (
...
<Bar
ref={this.chartReference}
...
/>
...
);
}