Skip to content

Instantly share code, notes, and snippets.

@rwbrockhoff
Last active May 29, 2020 07:36
Show Gist options
  • Save rwbrockhoff/0dabfa5f910a2a5f45597ea4599b51af to your computer and use it in GitHub Desktop.
Save rwbrockhoff/0dabfa5f910a2a5f45597ea4599b51af 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";
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
}
});
}
@QDERavi
Copy link

QDERavi commented May 29, 2020

Hi,
How can i create a global style config file ?
(Chart.defaults.global.defaultFontFamily = "'PT Sans', sans-serif")

and import in other chart component ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment