[英]React js and chart js pie chart type
Hello everyone i need to get a dynamic chart js pie type,大家好,我需要一个动态图表js pie类型,
this is the request to get the data:这是获取数据的请求:
async componentDidMount(){
axios.get("http://localhost:8080/requete/tab1")
.then(response => response.data)
.then((data) =>{
this.setState({dataL : data})
})
} }
this the code with static data:这是带有 static 数据的代码:
const options = {
animationEnabled: true,
exportEnabled: true,
theme: "light1",
title:{
text: "Trip Expenses"
},
data: [{
type: "pie",
indexLabel: "{label}: {y}%",
startAngle: -90,
dataPoints: [
{ y: 5, label: "Lost" },
{ y: 24, label: "Won" },
]
}]
}
please what i should to do to get the dynamic value at my chart请问我应该怎么做才能在我的图表上获得动态值
Try using react-apexcharts.尝试使用 react-apexcharts。 this lets you create dynamic charts as your wish
这使您可以根据需要创建动态图表
You should make new component with chart.js pie and define props
, too.您应该使用 chart.js 饼图制作新组件并定义
props
。 After receiving data from backend, you would import this component and send this data as props
.从后端接收数据后,您将导入此组件并将此数据作为
props
发送。
<Pie {...this.state.data} />
props: {
data: Array,
....
}
computed() {
pie() {
return this.data || [];
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.