React js和apexcharts未处理的拒绝TypeError无法读取未定义的属性'length'

时间:2020-07-16 13:35:21

标签: reactjs spring-boot hibernate charts apexcharts

我将apexcharts与react js和hibernate一起使用,所以这是方法: 后端弹簧靴:

   @GetMapping("/pieone")
    public String pieone()
    {Iterable<Closerfprfx> d =  cls.findAllDesign();
        Gson gson = new GsonBuilder().setPrettyPrinting().create();
        String jsonStr= gson.toJson(d);
        return jsonStr;}

这是我前端的代码:

 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>


      );
    }
  }

请执行以下操作来解决此错误,并获取带有json数据的动态图表js, 我希望在图形中显示处于Json模式的数据以显示动态数据

1 个答案:

答案 0 :(得分:0)

您在此处覆盖状态:

this.state = {
      
        series: this.state={
          dataL : []
          
        },