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. I am getting an error like "Uncaught Error: DOM element provided is null or undefined". I am new to plotly. Can somebody help me?
Solution:
Place the Javascript code (or reference to it) at the end of the HTML body.
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.
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'
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.