Skip to content

Instantly share code, notes, and snippets.

@gallirohik
Created January 31, 2019 18:53
Show Gist options
  • Save gallirohik/0b5e72d7d000382c252cf36f27510a7d to your computer and use it in GitHub Desktop.
Save gallirohik/0b5e72d7d000382c252cf36f27510a7d to your computer and use it in GitHub Desktop.
Dashboard project charts with react-chartjs-2
import React from "react";
import {Line} from 'react-chartjs-2'
function LineChart(props){
const count = props.chartData.map( data => data.count)
const labels = props.chartData.map( data => data.year+'/'+data.quarter)
const chartData = {
labels:labels,
datasets:[
{
label:'Population',
data:count,
backgroundColor:[
'rgba(255, 99, 132, 0.6)',
'rgba(54, 162, 235, 0.6)',
'rgba(255, 206, 86, 0.6)',
'rgba(75, 192, 192, 0.6)',
'rgba(153, 102, 255, 0.6)',
'rgba(255, 159, 64, 0.6)',
'rgba(255, 99, 132, 0.6)'
]
}
]
}
const chartOptions = {
title:{
display:true,
text:'JavaScript Pull Requests',
font:25
},
legend:{
display:true,
position:'bottom',
}
}
return (
<React.Fragment>
<h1>LineChart</h1>
<Line data={chartData} options={chartOptions} />
</React.Fragment>
);
}
export default LineChart;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment