Advertisement
Guest User

Untitled

a guest
Mar 20th, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. import React, { Component } from 'react'
  2. import Chart from "chart.js";
  3. import classes from "./LineGraph.module.css";
  4.  
  5. export default class LineGraph extends Component {
  6. chartRef = React.createRef();
  7.  
  8. componentDidMount() {
  9. const myChartRef = this.chartRef.current.getContext("2d");
  10.  
  11. new Chart(myChartRef, {
  12. type: "line",
  13. data: {
  14. //Bring in data
  15. labels: ["Jan", "Feb", "March"],
  16. datasets: [
  17. {
  18. label: "Sales",
  19. data: [86, 67, 91],
  20. }
  21. ]
  22. },
  23. options: {
  24. //Customize chart options
  25. }
  26. });
  27. }
  28. render() {
  29. return (
  30. <div className={classes.graphContainer}>
  31. <canvas
  32. id="myChart"
  33. ref={this.chartRef}
  34. />
  35. </div>
  36. )
  37. }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement