[echarts]: cartesian2d cannot be found for series.bar (index: 0).

175 阅读1分钟

解决方案

该报错通常为chartInstance被ref所包裹着,EX: const chartInstance = ref<Echarts | null>()。将其修改为let chartInstance:Echarts | null = null即可

原因:

用ref包裹着的instance创建了一个响应式代理。

事实上是:

{
    value: Proxy {
        [[Target]]:null,
        [[Handler]]: {...}
    }
}

当把echartInstance赋值给ref时 chartInstance.value = echarts.init(option)

echarts实例会被Proxy包裹。导致

  1. 方法调用被拦截
  2. 内部属性访问被拦截
  3. 原型链方法丢失

(该内容和原因仅供参考,如有不对感谢各位大佬前来纠正)