1👍
getNewData
is not bound to the class context, so the setState
will fail. you can use an arrow function so it will inherit the enclosing one.
getNewData = () => {
const min = 1;
const max = 10;
const rand = min + Math.floor(Math.random() * (max - min));
this.setState({
data: {
datasets: this.state.data.datasets.map((item, index) => ({
...item,
data: [...this.state.data.datasets[index].data, rand]
}))
}
});
}
- Chartjs-How to update css for doughnut chart with ng2-charts
- Chartjs-Django chart.js multi axis line chart
Source:stackexchange.com