简体   繁体   English

未捕获的错误:提供的 DOM 元素是 null 或在 plotly JS 中未定义

[英]Uncaught Error: DOM element provided is null or undefined in plotly JS

This is my Code:这是我的代码:

frequencywindow.webContents.executeJavaScript(`graphDiv = document.getElementById("myDiv");`)
var traceA = {
  x: [1, 2, 3, 4, 16, 17, 26],
  y: [1, 40, 9, 60, 4, 20, 10],
  type: 'scatter'
};
var data = [traceA];
var layout = {
  title:'A Line Chart in Plotly'
};
Plotly.plot( graphDiv, data, layout );

I am using plotly in my electron application.我在我的 electron 应用程序中使用 plotly。 I am getting an error like "Uncaught Error: DOM element provided is null or undefined".我收到类似“未捕获的错误:提供的 DOM 元素是 null 或未定义”的错误。 I am new to plotly.我是 plotly 的新手。 Can somebody help me?有人可以帮助我吗?

Solution:解决方案:

Place the Javascript code (or reference to it) at the end of the HTML body.将 Javascript 代码(或引用它)放在 HTML 主体的末尾。

Explanation:解释:

Uncaught Error: DOM element provided is null or undefined means that the HTML element with id='myDiv' is not present on the HTML page at the time when the Javascript code is being executed. Uncaught Error: DOM element provided is null or undefined means that the HTML element with id='myDiv' is not present on the HTML page at the time when the Javascript code is being executed.

By placing the Javascript code at the end of the HTML body, you let the whole HTML page load before calling the code, and thus, the code can "see" the HTML element with id='myDiv' . By placing the Javascript code at the end of the HTML body, you let the whole HTML page load before calling the code, and thus, the code can "see" the HTML element with id='myDiv' .

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 React.js未捕获的错误:_registerComponent(…):目标容器不是DOM元素 - React.js Uncaught Error: _registerComponent(…): Target container is not a DOM element 未捕获的错误:createRoot(...):目标容器不是 DOM 元素 - Uncaught Error: createRoot(...): Target container is not a DOM element 未捕获的错误:目标容器不是 DOM 元素 - Uncaught Error: Target container is not a DOM element 未捕获的错误:_registerComponent(...):目标容器不是DOM元素 - Uncaught Error: _registerComponent(…): Target container is not a DOM element React - 未捕获的错误:目标容器不是 DOM 元素 - React - Uncaught Error: Target container is not a DOM element Tinymce 未捕获错误:节点不能为空或未定义 - Tinymce Uncaught Error: Node cannot be null or undefined Reactjs错误:babel-runtime.js:32 Uncaught TypeError:超级表达式必须为null或函数,而不是未定义 - Reactjs error: babel-runtime.js:32 Uncaught TypeError: Super expression must either be null or a function, not undefined 未捕获类型:未定义不是函数JS错误 - Uncaught Type: Undefined is not a function JS error 未捕获的错误:元素缓存中ID为x的DOM元素与DOM中的元素不同 - Uncaught Error: DOM element with id x in Element cache is not same as element in DOM 反应-laravel-未捕获的错误:目标容器不是DOM元素 - React - laravel - Uncaught Error: Target container is not a DOM element
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM