Skip to content

Instantly share code, notes, and snippets.

@rwbrockhoff
Last active March 16, 2019 00:02
Show Gist options
  • Save rwbrockhoff/b157cf9dfe84099f12e2aa18a2019f81 to your computer and use it in GitHub Desktop.
Save rwbrockhoff/b157cf9dfe84099f12e2aa18a2019f81 to your computer and use it in GitHub Desktop.
import React, { Component } from 'react'
import Chart from "chart.js";
import classes from "./LineGraph.module.css";
export default class LineGraph extends Component {
chartRef = React.createRef();
componentDidMount() {
const myChartRef = this.chartRef.current.getContext("2d");
new Chart(myChartRef, {
type: "line",
data: {
//Bring in data
labels: ["Jan", "Feb", "March"],
datasets: [
{
label: "Sales",
data: [86, 67, 91],
}
]
},
options: {
//Customize chart options
}
});
}
render() {
return (
<div className={classes.graphContainer}>
<canvas
id="myChart"
ref={this.chartRef}
/>
</div>
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment