【问题标题】:React js and apexcharts Unhandled Rejection TypeError Cannot read property 'length' of undefinedReact js和apexcharts Unhandled Rejection TypeError无法读取未定义的属性“长度”
【发布时间】:2020-07-16 13:35:21
【问题描述】:

我使用带有 react js 和 hibernate 的 apexcharts,所以这是方法: 后端弹簧启动:

   @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 模式的数据以进行动态数据显示

【问题讨论】:

    标签: reactjs spring-boot hibernate charts apexcharts


    【解决方案1】:

    你在这里覆盖了状态:

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

    【讨论】:

      猜你喜欢
      • 2020-07-20
      • 2020-03-07
      • 2021-10-03
      • 1970-01-01
      • 2020-06-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多