echarts js报错 Cannot read property 'getAttribute' of null

Posted dongsir

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了echarts js报错 Cannot read property 'getAttribute' of null相关的知识,希望对你有一定的参考价值。

本文将为您描述如何解决 eharts.js报错 Uncaught TypeError: Cannot read property \'getAttribute\' of null 的问题

 

根据报错信息查找原因发现是因为 实例化 echarts 的元素不存在(未找到指定的元素),查看官方文档发现:

// 基于准备好的dom,初始化echarts实例
var myChart = echarts.init(document.getElementById(\'main\'));

基于准备好的 dom,初始化 echarts 实例,也就是只有 页面存在的html元素 才可以去初始化。

解决方案:

HTML DOM getElementById() 方法 (通过 指定ID查找元素),在 初始化echarts 之前打印一下看看此元素是否存在

例:

console.log(document.getElementById(\'main\'))

 

以上是关于echarts js报错 Cannot read property 'getAttribute' of null的主要内容,如果未能解决你的问题,请参考以下文章

解决vue3中使用echart echart报错:Cannot read properties of undefined (reading ‘type‘)

解决vue3中使用echart echart报错:Cannot read properties of undefined (reading ‘type‘)

Echarts报错 Cannot read property ‘init’ of undefined

java中echarts关系图中如何引用dataTool:Uncaught TypeError: Cannot read property 'gexf' of undefined

在vue中使用echarts报错"TypeError: Cannot read property 'getAttribute' of null

Echarts 明明和官方文档配置一致,图表加载却是报错:Error in mounted hook: "TypeError: Cannot read property 'get&#