Last active
March 16, 2019 00:02
-
-
Save rwbrockhoff/b157cf9dfe84099f12e2aa18a2019f81 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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