簡體   English   中英

未捕獲的錯誤:提供的 DOM 元素是 null 或在 plotly JS 中未定義

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

這是我的代碼:

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 );

我在我的 electron 應用程序中使用 plotly。 我收到類似“未捕獲的錯誤:提供的 DOM 元素是 null 或未定義”的錯誤。 我是 plotly 的新手。 有人可以幫助我嗎?

解決方案:

將 Javascript 代碼(或引用它)放在 HTML 主體的末尾。

解釋:

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' .

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM