[英]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.