[英]Apexcharts - React js Unhandled Rejection (TypeError): t.every is not a function
I'm trying to set dynamic data into my pie chart using Apexcharts, but I'm running into an error.我正在尝试使用 Apexcharts 将动态数据设置到我的饼图中,但我遇到了错误。
class ApexChartPie1 extends React.Component {
constructor(props) {
super(props);
this.state = {
series: this.state={
dataL : []
},
options: {
chart: {
width: 380,
type: 'pie',
},
labels: ['LOST', 'WON'],
responsive: [{
breakpoint: 480,
options: {
chart: {
width: 200
},
legend: {
position: 'bottom'
}
}
}]
},
};
}
async componentDidMount(){
axios.get("http://localhost:8080/designe/pieone")
.then(response => response.data)
.then((data) =>{
this.setState({dataL : data})
})
}
render() {
return (
<div id="chart">
<ReactApexChart options={this.state.options} series={this.state.series} type="pie" width={380} />
</div>
);
}
}
The error I'm getting:我得到的错误:
React js Unhandled Rejection (TypeError): t.every is not a function
One problem that I see is that you are nesting references to this.state
and Apexcharts is looking for series
to be an array of chart values.我看到的一个问题是您正在嵌套对
this.state
的引用,而 Apexcharts 正在寻找作为图表值数组的series
。
You could try changing your setup in the constructor:您可以尝试在构造函数中更改设置:
this.state = {
series: [],
options: {
// Your options
}
};
And then add your data in the Axios call with:然后在 Axios 调用中添加您的数据:
this.setState({series: data})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.