Level Up Coding

Coding tutorials and news. The developer homepage gitconnected.com && skilled.dev && levelup.dev

Follow publication

Member-only story

How to Setup Chart.js for React and Dynamically Allocate Colors

Nicolai Safai
Level Up Coding
Published in
4 min readMay 15, 2019

--

Why Use Chart.js?

Source

How to Use Chart.js with React

npm install react-chartjs-2 chart.js --save// ORyarn add react-chartjs-2 chart.js
import {Bar} from 'react-chartjs-2';

< Bar data={...} />

How to Prepare Your Data

data = {
labels: ["January", "February", "March", "April", "May", "June", "July"],
datasets: [{
label: "My First dataset",
backgroundColor: 'rgb(255, 99, 132)',
borderColor: 'rgb(255, 99, 132)',
data: [0, 10, 5, 2, 20, 30, 45],
}]
}

--

--

Written by Nicolai Safai

Software Engineer | PM | Interested in Music, Design, Psychology & Education. “Make it Happen Captain”

No responses yet