[英]plotting pie chart with reactjs and chart.js
i am trying to plot the pie chart using some dummy data. 我正在尝试使用一些虚拟数据绘制饼图。 my react chart component looks like this:- 我的反应图组件看起来像这样:
import React, {Component} from 'react';
import {Bar,Line,Pie} from 'react-chartjs-2';
class Chart extends Component {
constructor(props){
super(props);
this.state = {
chartData :props.chartData
}
console.log("props data ",props.chartData)
}
render(){
return(
<Pie
data={this.state.chartData}
options={{
title:'cool pie chart',
text:"coolest data"
}}
/>
);
}
}
export default Chart;
and i think the data passed on component is also absolutely fine. 而且我认为通过组件传递的数据也绝对不错。
but currently i can only plot the labels. 但目前我只能绘制标签。 like this:- 像这样:-
what am i missing ? 我想念什么?
Use react-chartjs
rather than react-chartjs-2
. 使用react-chartjs
而不是react-chartjs-2
。 It works like a charm 它像一个魅力
Check the live demo here - https://stackblitz.com/edit/react-p2bb24?embed=1&file=index.js 在此处查看实时演示-https: //stackblitz.com/edit/react-p2bb24?embed=1&file=index.js
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.