Chartjs-(Lifecycle problem?) React Chart js-2 not updating data from componentDidMount

1👍

you have to update the state after changing the datasets,

pushAction = () => {
  const dataState = this.state.data;
  const oldDataTotal = this.state.data.datasets[0].data;
  const oldDataGood = this.state.data.datasets[1].data;

  oldDataTotal.push(this.state.provider[0].huluAction);
  oldDataTotal.push(this.state.provider[0].huluAnime);
  oldDataTotal.push(this.state.provider[0].huluChildren);

  oldDataGood.push(this.state.provider[0].Action);
  oldDataGood.push(this.state.provider[0].Anime);
  oldDataGood.push(this.state.provider[0].Children);

  this.setState({data: {...dataState, datasets : [...oldDataTotal, oldDataGood]}});
}

Leave a comment