DEV Community

Cover image for Create a Chart with multiple Dataset switching via state [React + react-chartjs-2 Tutorial]
Chris Godber
Chris Godber

Posted on

1 1

Create a Chart with multiple Dataset switching via state [React + react-chartjs-2 Tutorial]


SOURCECODE- https://github.com/drnoir/switchingcharts-demo

This tutorial goes over a basic overview of a method to create a chart in a class component in react using react-chartjs-2 and how to update the chart with different data using SetState within that chart based on onClick events within the component - in this example 3 months, 6 months and a year.

In a real life example you would probably get your data from props, or state but this should provide a good starting point for understanding how to do this.

Top comments (0)

Heroku

This site is built on Heroku

Join the ranks of developers at Salesforce, Airbase, DEV, and more who deploy their mission critical applications on Heroku. Sign up today and launch your first app!

Get Started

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay