gpt4 book ai didi

javascript - Apexcharts - React js Unhandled Rejection (TypeError) : t. 每个都不是函数

转载 作者:行者123 更新时间:2023-12-05 00:39:26 26 4
gpt4 key购买 nike

我正在尝试使用 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>
);
}
}
我得到的错误: React js Unhandled Rejection (TypeError): t.every is not a function

最佳答案

我看到的一个问题是您正在嵌套对 this.state 的引用。 Apexcharts 正在寻找 series成为图表值的数组。
您可以尝试在构造函数中更改设置:

this.state = {
series: [],
options: {
// Your options
}
};
然后在 Axios 调用中添加您的数据:
this.setState({series: data})

关于javascript - Apexcharts - React js Unhandled Rejection (TypeError) : t. 每个都不是函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62957957/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com