简体   繁体   English

图表 JS 错误:未捕获的类型错误:无法读取未定义的属性“顶部”

[英]Chart JS Error : Uncaught TypeError: Cannot read property 'top' of undefined

This is the first time I am using JS and need to use jQuery and Chart Js for plotting a time series., but I keep getting the following error:这是我第一次使用 JS 并且需要使用 jQuery 和 Chart Js 来绘制时间序列。但我不断收到以下错误:

Uncaught TypeError: Cannot read property 'top' of undefined
    at callFllSamplesApi (plot.js:105)

Code Block:代码块:

//Script included before body tag  (Chart.js 2.4, jQuery 3.4, local file plot.js with callFllSamplesApi() )

<body>
        <canvas id="line-chart" width="450" height="500"></canvas>
        <button id="btn1" onclick="callFllSamplesApi()">Generate FLL Graph</button>
 </body>

Function callFLLSamplesApi is shown below with the line that throws error.函数 callFLLSamplesApi 如下所示,其中包含引发错误的行。

function callFllSamplesApi() {

    var request = new XMLHttpRequest()
    request.open('GET', 'http://193.142.33.4/api/samples', true)
    request.onload = function(){
        ... Parsing code         
    }
    request.send()
    var ctx = document.getElementById("line-chart");
    var myChart = new Chart(ctx, {  <- Line 105 which throws an error
        ... More code for plotting
            }
        }
    });
}

You are missing getContext() on your line-chart element您的折线图元素缺少getContext()

var ctx = document.getElementById("line-chart").getContext('2d');

https://www.chartjs.org/docs/latest/ https://www.chartjs.org/docs/latest/

暂无
暂无

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

相关问题 未捕获的类型错误:无法读取未定义的属性“offsetWidth” - chart.js - Uncaught TypeError: Cannot read property 'offsetWidth' of undefined - chart.js Uncaught TypeError:无法读取未定义的属性“ top”-滚动错误? - Uncaught TypeError: Cannot read property 'top' of undefined - Scrolling error? 控制台错误:未捕获TypeError:无法读取未定义的属性“顶部” - Console Error: Uncaught TypeError: Cannot read property 'top' of undefined 未捕获的TypeError:无法读取未定义错误的属性“ top” - Uncaught TypeError: Cannot read property 'top' of undefined error Javascript 错误未捕获类型错误:无法读取未定义的属性“顶部” - Javascript Error Uncaught TypeError: Cannot read property 'top' of undefined 错误:未被捕获的TypeError:无法读取未定义的属性“顶部” - Error: Uncaught TypeError: Cannot read property 'top' of undefined 导航菜单错误“未捕获的TypeError:无法读取未定义的属性&#39;top&#39;” - Navigation Menu Error “Uncaught TypeError: Cannot read property 'top' of undefined” 未捕获的类型错误:无法读取未定义的属性“顶部” - Uncaught TypeError: Cannot read property ‘top’ of undefined 未捕获的TypeError:无法读取未定义的属性“ top” - Uncaught TypeError: Cannot read property 'top' of undefined 未捕获的TypeError:无法读取未定义的属性“ top” - Uncaught TypeError: Cannot read property 'top' of undefined
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM