0👍
function has its own this context so you either have to store the this context in a local variable before the setInterval or use an arrow function instead of function
setInterval(() => {
this.props.changeHandler();
}, 500);
- Chartjs-How to display name on multi series pie chart in chartjs
- Chartjs-How to change React line chart tooltip title font family in chart.js
0👍
First you need to obtain a reference to the Chart.js instance.
constructor() {
...
this.chartReference = React.createRef();
...
}
render() {
return (
<Doughnut ref={this.chartReference} data={this.state.data} />
)
}
From this reference, you can obtain the chart instance, update its data
and finally invoke chart.update()
.
setInterval(() => {
const chart = this.chartReference.current.chartInstance;
chart.data.datasets[0].data = [<the new data>];
chart.update();
}, 2000);
Please take a look at this StackBlitz and see how it works.
Source:stackexchange.com