echarts icon indicating copy to clipboard operation
echarts copied to clipboard

Cannot read property 'getRawIndex' of undefined

Open lolivia opened this issue 8 years ago • 27 comments

One-line summary [问题简述]

饼图未完全渲染,即饼图动态变化时,鼠标hover到饼图的扇区,报错Cannot read property 'getRawIndex' of undefined, 但不影响渲染以及后续使用

Version & Environment [版本及环境]

  • ECharts version [ECharts 版本]: 4.1.0
  • Browser version [浏览器类型和版本]: 70.0.3538.77
  • OS Version [操作系统类型和版本]: mac

Expected behaviour [期望结果]

不输出该错误

ECharts option [ECharts配置项]

option = {
   tooltip: {
      show: true,
      formatter: (params) => {....},
  }
  series: [{
     name: '计数',
      type: 'pie',
      center: ['50%', '50%'],
      data: [{
       .......
       }]
   }]
  }
}

比较特殊的是 我的数据是远程获取,并且数据比较大,当整个饼图渲染完,并没有变化的时候,鼠标hover上去不会有什么错误,但是当数据还在加载的时候,饼图还在变化,这个时候鼠标hover上去会报错。 错误如下

Other comments [其他信息]

dataFormat.js?6c1b:40 Uncaught TypeError: Cannot read property 'getRawIndex' of undefined at ExtendedClass.getDataParams (dataFormat.js?6c1b:40) at Function.superCall (clazz.js?04d6:107) at ExtendedClass.getDataParams (PieSeries.js?fef3:78) at ECharts.eval (echarts.js?21c7:1386) at Handler.trigger (Eventful.js?aa3b:158) at Handler.dispatchToElement (Handler.js?963e:218) at Handler.mouseout (Handler.js?963e:135) at HandlerDomProxy.trigger (Eventful.js?aa3b:158) at HandlerDomProxy.mouseout (HandlerProxy.js?7bcf:107) at HTMLDivElement.eval (HandlerProxy.js?7bcf:245) getDataParams @ dataFormat.js?6c1b:40 superCall @ clazz.js?04d6:107 getDataParams @ PieSeries.js?fef3:78 (anonymous) @ echarts.js?21c7:1386 trigger @ Eventful.js?aa3b:158 dispatchToElement @ Handler.js?963e:218 mouseout @ Handler.js?963e:135 trigger @ Eventful.js?aa3b:158 mouseout @ HandlerProxy.js?7bcf:107 (anonymous) @ HandlerProxy.js?7bcf:245

lolivia avatar Nov 14 '18 12:11 lolivia

Please provide a full example at jsfiddle or http://gallery.echartsjs.com/editor.html . I tried to add animationDuration: 5000 to slow down the animation and hover on pie before the animation completed and cannot reproduce it.

Ovilia avatar Nov 15 '18 02:11 Ovilia

不好意思 ,我们的场景比较复杂,不太好描述,如果单纯的写options,也确实不会出现这种问题,我想问下,因为我看到代码出错的地方是 var data = this.getData(dataType);这里为undefined,不知道是不是我姿势用的不对, 一般什么情况下 这里会undefined呢 image

lolivia avatar Nov 15 '18 14:11 lolivia

I cannot tell from the provided information. Please debug by yourself with ECharts repo node build/build.js.

Ovilia avatar Nov 16 '18 03:11 Ovilia

same for me

propakov avatar Dec 04 '18 09:12 propakov

@Pavel-Ropakov Can you provide your option?

Ovilia avatar Dec 11 '18 06:12 Ovilia

same for me

lixueying avatar Apr 03 '19 10:04 lixueying

Getting this also, not sure what the problem is.

braco avatar May 12 '19 01:05 braco

same for me

j4dream avatar May 20 '19 09:05 j4dream

same for me

wustdjf avatar Aug 14 '19 12:08 wustdjf

same for me

xushimin avatar Aug 27 '19 13:08 xushimin

image e.target.dataType 为undefined

xushimin avatar Aug 27 '19 13:08 xushimin

Same thing happening for me too. I have debugged it to this function. Task appears to be null here. And this function is returning undefined.

Series.js

  getData: function (dataType) {
    var task = getCurrentTask(this);

    if (task) {
      var data = task.context.data;
      return dataType == null ? data : data.getLinkedData(dataType);
    } else {
      // When series is not alive (that may happen when click toolbox
      // restore or setOption with not merge mode), series data may
      // be still need to judge animation or something when graphic
      // elements want to know whether fade out.
      return inner(this).data;
    }
  }

ankushjamdagani avatar Sep 17 '19 07:09 ankushjamdagani

I'm seeing the same on echarts 4.1.0 and 4.3.0 and echarts-for-react 2.0.14, echarts-for-react 2.0.15-beta.0, specifically using a Pie Chart. Can this issue be re-opened?

mechmillan avatar Sep 19 '19 15:09 mechmillan

Issue Reason

I was passing every dynamic config toecharts-for-react component as a prop. Config consited of 1...3 number of series. Exception was raised when the new config doesn't consist of a series present previously and moving mouse over that series.

Obvious Solution

Stop the event handling when chart is updating.

Fix 1

Show an overlay over chart when it is updating.

  1. chartInstance.showLoading() when change has started. (I did it as soon as the API call for next data is triggered)
  2. chartInstance.hideLoading() when chartInstance.on('finished') event.

Fix 2

chartInstance.setOption does the update with silent (no-event-listening) mode. https://www.echartsjs.com/en/api.html#echartsInstance.setOption

  1. Pass initial config as prop to Echart component.
  2. For next changes, use chartInstance.setOptions(...) instead of passing new config as prop to the component.

Hope this is of use to you guys.

ankushjamdagani avatar Sep 19 '19 18:09 ankushjamdagani

Anyone could provide a demo for this issue?

Ovilia avatar Sep 24 '19 09:09 Ovilia

same for me

hujinbo avatar Oct 28 '19 14:10 hujinbo

I use ReactEcharts and had similar problem with 'scatter' and 'bar' series. Likely because events are being dispatched while the chart is re-rendering. After setting silent: false to the series, the error was eliminated. But this disabled tooltip too.

This works for me: use a React shouldComponentUpdate method to prevent Echarts from re-rendering.

anachronin avatar Nov 28 '19 01:11 anachronin

I have the same error and the error disappeared when i deleted lazyUpdate from options

I use echarts-for-react v2.0.16

eslambasher avatar May 14 '21 10:05 eslambasher

set : silent: true , maybe it work

hongdeyuan avatar Sep 15 '21 08:09 hongdeyuan

setOption(option: Opt, notMerge?: boolean, lazyUpdate?: boolean): void; I passed "notMerge" into "true", this problem occurred, changed to "false", the problem was solved

a1292999652 avatar Dec 10 '21 03:12 a1292999652