通过异步获取了数据设置到echart饼图上饼图全成全黑色

出现的问题是当不异步获取数据时,其颜色可以正常显示,部分代码及效果如下:

setOptions({ expectedData, actualData } = {}) {
      this.chart.setOption({
        tooltip: {
          trigger: "item",
          formatter: "{a} <br/>{b} : {c} ({d}%)"
        },

        visualMap: {
          show: false,
          min: 80,
          max: 600,
          inRange: {
            colorLightness: [0, 1]
          }
        },
        series: [
          {
            name: "访问来源",
            type: "pie",
            radius: "85%",
            center: ["50%", "45%"],
            data: [
              { value: 335, name: "钢混" },
              { value: 310, name: "砖混" },
              { value: 274, name: "水泥" },
              { value: 235, name: "钢筋" }
            ].sort(function(a, b) {
              return a.value - b.value;
            }),
            roseType: "angle",
            label: {
              normal: {}
            },
            labelLine: {
              normal: {
                smooth: 0.2,
                length: 10,
                length2: 20
              }
            }
          }
        ],
        animationDuration: 2800,
        animationEasing: "cubicInOut"
      });
    },

clipboard.png

但是当异步获取了数据并绑定时,饼图变成了全黑色,不知道原因是什么,我的异步设置代码和最后效果如下,其中getData方法的调用也附在下面:

  mounted() {
    this.initChart();
    this.getData();
    if (this.autoResize) {
      this.__resizeHanlder = _.debounce(() => {
        if (this.chart) {
          this.chart.resize();
        }
      }, 100);
      window.addEventListener("resize", this.__resizeHanlder);
    }
  },
// getData方法
    getData() {
      let params = {
        paramTypeId: 1
      };
      this.chart.showLoading();
      getHouseParamCount(params).then(res => {
        console.log(res.data.data)
        this.chart.setOption({
          series: {
            data: res.data.data.content
          }
        });
        this.chart.hideLoading();
      });
    },

clipboard.png

阅读 4.2k
1 个回答

发现问题好像是echart的原因,当换了一个示例时可以正常显示颜色了

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题