Skip to content

Attempting to update Chart.js chart in React using react-chartjs-2, doc is unclear #411

Not planned

Description

@jscheinhorn

Hello,
I'm just getting started with chart-reactjs-2. I am dynamically loading data onto the chart and need it to update with each render.

I read the following:

 chartReference = {};
 
componentDidMount() {
  console.log(this.chartReference); // returns a Chart.js instance reference
}
 
render() {
  return (<Doughnut ref={(reference) => this.chartReference = reference } data={data} />)

and would like to do something like:

let lineChart = this.chartReference.chartInstance
lineChart.update();

but I don't know what to include within chartReference. Any guidance is greatly appreciated!

Activity

  1. changed the title [-]Attempting to update chart, doc is unclear[/-] [+]Attempting to update Chart.js chart in React using react-chartjs-2, doc is unclear[/+] on Jun 23, 2019
  2. pringelmann commented on Dec 3, 2019

    @pringelmann
    Collaborator

    @jscheinhorn Is there a specific reason you need to imperatively call the update() method on each render call? If your data prop changes then the wrapper will automatically update the chart: https://github.com/jerairrest/react-chartjs-2/blob/master/src/index.js#L237

  3. dangreen commented on Nov 30, 2026

    @dangreen
    Collaborator

    Closing: this is a usage question rather than a bug report or a feature request. The docs of the wrapper are at https://react-chartjs-2.js.org and the chart options are described in the Chart.js docs: https://www.chartjs.org/docs/latest/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions