简体   繁体   English

Apexcharts - React js 未处理的拒绝(TypeError):t.every 不是 function

[英]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.

相关问题 未处理的拒绝(TypeError):调度不是 function 反应 js - Unhandled Rejection (TypeError): dispatch is not a function react js 反应-未处理的拒绝(TypeError):_this4.getNotes不是函数 - React - Unhandled Rejection (TypeError): _this4.getNotes is not a function 如何修复未处理的拒绝(TypeError):chat.setUser 不是 Firechat 中的 function 由 React.js 中的 Firebase - How to Fix Unhandled Rejection (TypeError): chat.setUser is not a function in Firechat by Firebase in React.js 未处理的拒绝(TypeError):setToken 不是函数 - Unhandled Rejection (TypeError): setToken is not a function 未处理的拒绝 (TypeError):setDailyData 不是函数 - Unhandled Rejection (TypeError): setDailyData is not a function REACT JS:未处理的拒绝(TypeError):无法读取未定义的属性“数据” - REACT JS: Unhandled Rejection (TypeError): Cannot read property 'data' of undefined 未处理的拒绝(TypeError):Object(...) 不是函数 - Unhandled Rejection (TypeError): Object(...) is not a function 未处理的拒绝(TypeError):setX 不是 function - Unhandled Rejection (TypeError): setX is not a function React - 未处理的拒绝(TypeError):e.preventDefault 不是 function - React - Unhandled Rejection (TypeError): e.preventDefault is not a function React 功能组件父子 - 未处理的拒绝(TypeError):X 不是 function - React Functional Component Parent and Child - Unhandled Rejection (TypeError): X is not a function
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM