Last active
May 29, 2020 07:36
-
-
Save rwbrockhoff/0dabfa5f910a2a5f45597ea4599b51af 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"; | |
let myLineChart; | |
//--Chart Style Options--// | |
Chart.defaults.global.defaultFontFamily = "'PT Sans', sans-serif" | |
Chart.defaults.global.legend.display = false; | |
//--Chart Style Options--// | |
export default class LineGraph extends Component { | |
chartRef = React.createRef(); | |
componentDidMount() { | |
this.buildChart(); | |
} | |
componentDidUpdate() { | |
this.buildChart(); | |
} | |
buildChart = () => { | |
const myChartRef = this.chartRef.current.getContext("2d"); | |
const { data, average, labels } = this.props; | |
if (typeof myLineChart !== "undefined") myLineChart.destroy(); | |
myLineChart = new Chart(myChartRef, { | |
type: "line", | |
data: { | |
//Bring in data | |
labels: labels, | |
datasets: [ | |
{ | |
label: "Sales", | |
data: data, | |
fill: false, | |
borderColor: "#6610f2" | |
}, | |
{ | |
label: "National Average", | |
data: average, | |
fill: false, | |
borderColor: "#E0E0E0" | |
} | |
] | |
}, | |
options: { | |
//Customize chart options | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi,
How can i create a global style config file ?
(Chart.defaults.global.defaultFontFamily = "'PT Sans', sans-serif")
and import in other chart component ...