【发布时间】:2020-11-04 21:02:22
【问题描述】:
我在我的 react 项目中使用 Chart.js。 我想通过创建组件来尽可能整齐地构建我的项目 并在我的 App.js 上调用它们
如何在不从 App.js 实际调用我的饼图的情况下创建一个 react prop 并从另一个组件调用它
import React from 'react';
import {Pie} from 'react-chartjs-2';
const state = {
labels: ['January', 'February', 'March',
'April', 'May'],
datasets: [
{
label: 'Rainfall',
backgroundColor: [
'#B21F00',
'#C9DE00',
'#2FDE00',
'#00A6B4',
'#6800B4'
],
hoverBackgroundColor: [
'#501800',
'#4B5000',
'#175000',
'#003350',
'#35014F'
],
data: [65, 59, 80, 81, 56]
}
]
}
export default class App extends React.Component {
render() {
return (
<div>
<Pie
data={state}
options={{
title:{
display:true,
text:'Average Rainfall per month',
fontSize:20
},
legend:{
display:true,
position:'left',
}
}}
/>
</div>
);
}
}
【问题讨论】:
标签: reactjs react-native chart.js react-chartjs