I'm trying to implement a pie chart in my web application and i found this as a good source.
https://github.com/reactjs/react-chartjs
But it does not provide the way to give chartData
and chartOptions
inorder to make it work. How can i do this?
my code
import React, {Component} from 'react';
var LineChart = require("react-chartjs").Line;
class PieChart extends Component {
constructor() {
super();
}
render() {
return (
<div className="">
<LineChart data={chartData} options={chartOptions} width="600" height="250"/>
</div>
);
}
}
export default PieChart;
I get these errors
12:34 error 'chartData' is not defined no-undef
12:54 error 'chartOptions' is not defined no-undef
You need to initialise
chatData
andchartOptions
and alsoreact-chartjs
has a dependency onchartjs
, so you need to install that tooCode
I use chart.js in my project and it works really well. You need install chart.js module via npm
Then import it to your component file
And it provides 'data' field in its function for you to populate data.
For more details please check the their doc (http://www.chartjs.org/docs/)