echarts icon indicating copy to clipboard operation
echarts copied to clipboard

Cannot read property '__ecGraphicWidth' of null

Open yeahe83 opened this issue 9 years ago • 2 comments

One-line summary [问题简述]

在window.onresize中对graphic进行操作时,出现‘Cannot read property '__ecGraphicWidth' of null’的错误。似乎3.5.3时还正常。

Version & Environment [版本及环境]

  • ECharts version [ECharts 版本]: 3.6.2
  • Browser version [浏览器类型和版本]: Chrome 59
  • OS Version [操作系统类型和版本]: win10

Expected behaviour [期望结果]

不报错

ECharts option [ECharts配置项]

var option = {
  graphic: {
    id: 'text1',
    type: 'rect',
    shape: {
      x:0,
      y:0,
      width: 100,
      height: 100,
    },
    style: {
      fill: 'red',
    }
  },
};

var myChart = echarts.init(document.getElementById('main'));
myChart.setOption(option);

window.onresize = function() {
  document.getElementById('wid').innerText = window.innerWidth;
  var option = myChart.getOption();
  if (window.innerWidth < 600) {
    option.graphic = { // 删除上例中定义的 'text1' 元素。
      id: 'text1',
      $action: 'remove'
    }
  }
  else {
    option.graphic = {
      id: 'text1',
      type: 'rect',
      shape: {
        x:0,
        y:0,
        width: 100,
        height: 100,
      },
      style: {
        fill: 'red',
      }
    }
  }
  myChart.setOption(option);
}

window.onresize();

Other comments [其他信息]

https://jsfiddle.net/yeahe83/5ue92077/

yeahe83 avatar Jul 20 '17 06:07 yeahe83

你可以改用 window事件监听,或是,写一个js方法,通过监听 获取到的 width 的值,如果值大于 600,再去调echarts图表试一下。

CWSchen avatar Jul 20 '17 07:07 CWSchen

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Apr 02 '20 23:04 stale[bot]