React|Echarts|Antd|在Modal中展示echarts不显示的问题

打开modal时echarts部分空白:

解决方法:使用ref绑定div,dom存在时再draw

           <div
              id="quintuple"
              style={{
                width: "450px",
                height: "350px",
              }}
              ref={modalRef}
            />

  const modalRef = (obj) => {
    if (obj) {
      drawChart(obj, [
        {
          value: [
            info.question || 10,
            info.theoretical_method || 10,
            info.practical_method || 10,
            info.effects || 10,
            info.conclusion || 10,
          ],
        },
      ]);
    }
  };

function drawChart(dom, data) {
  let myChart = echarts.getInstanceByDom(dom); //有的话就获取已有echarts实例的DOM节点。
  if (myChart == null) {
    // 如果不存在,就进行初始化。
    myChart = echarts.init(dom);
  }
  //此处省略数据处理过程
  let option = {
    angleAxis: {
      startAngle: 0,
    },
    radiusAxis: {
      type: "value",
      min: 0,
      max: 100,
      z: 1,
    },
    polar: {
      radius: 100,
    },
    radar: {
      shape: "circle",
      radius: 100,
      color: "black",
      indicator: [
        {
          name: "Problem",
          max: 100,
        },
        {
          name: "Theoretical Method",
          max: 100,
        },
        {
          name: "Practical Method",
          max: 100,
        },
        {
          name: "Effects",
          max: 100,
        },
        {
          name: "Conclusion",
          max: 100,
        },
      ],
      axisName: {
        color: "black",
      },
      axisNameGap: 20,
    },
    series: [
      {
        // name: "Five-dimensional analysis",
        type: "radar",
        data: data,
        areaStyle: {
          color: "#0068c9",
          opacity: 0.2,
        },
        label: {
          show: true,
        },
      },
    ],
  };
  option && myChart.setOption(option);
}

相关推荐

  1. react引用echarts

    2024-04-04 12:04:03       56 阅读
  2. 解决echartsuniapp里tooltip,legend能点击问题

    2024-04-04 12:04:03       20 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-04-04 12:04:03       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-04-04 12:04:03       100 阅读
  3. 在Django里面运行非项目文件

    2024-04-04 12:04:03       82 阅读
  4. Python语言-面向对象

    2024-04-04 12:04:03       91 阅读

热门阅读

  1. C++4.2

    2024-04-04 12:04:03       30 阅读
  2. os模块篇(十二)

    2024-04-04 12:04:03       32 阅读
  3. 5.108 BCC工具之virtiostat.py解读

    2024-04-04 12:04:03       35 阅读
  4. .net 实现的 Webscoket 对象的一些细节和疑问

    2024-04-04 12:04:03       41 阅读
  5. Ideal Holidays

    2024-04-04 12:04:03       38 阅读
  6. Sora文本生成视频(附免费的专属提示词)

    2024-04-04 12:04:03       41 阅读
  7. PyTorch示例——使用Transformer写古诗

    2024-04-04 12:04:03       31 阅读