【发布时间】:2017-06-24 07:32:34
【问题描述】:
我已经包含了 jquery,然后所有 ui js 文件作为少数线程表明此错误是由于依赖关系。用户上传照片时使用canvasjs绘制图形。
Uncaught TypeError: Cannot read property 'getTime' of undefined
包含所有必需依赖项的引导 html。我认为某些循环问题或变量未正确传递,但console.log根据canvasjs的所需数据点显示有效的json。如果这些点直接嵌入到该数据点图中,则生成没有任何错误或问题。
我也尝试更新 canvasjs 的功能但不起作用,我认为这不是必需的,因为这些数据已成功传递,因此不会传递空白数据。我怀疑 for 循环是罪魁祸首,但不知道如何以及为什么
$(document).ready(function() {
(function() {
$('#upload-form2').ajaxForm({
dataType: 'json',
success: function(data) {
var sthtml;
var html = '',
downlo;
for (var i = 0; i < data.length; i++) {
z = i + 1;
downlo = data[i];
html += '<tr id="' + i + '"><td>' + z + '</td></tr>';
sthtml += downlo.stchart;
}
// canvas graph starts here
var chart = new CanvasJS.Chart("chartContainer",
{
theme:"theme2",
title:{
text: "Game of Thrones, Viewers of the first airing on HBO"
},
data: [
{
type: "spline",
dataPoints: [sthtml]
// this is the culprit dont know why but console.log shows correct canvasjs.min.js:103 Uncaught TypeError: Cannot read property 'getTime' of undefined
// dataPoints: [{ x: 3, y: 150 },{ x: 2, y: 14}]
//gives no error however my console.log output is exactly same in last line of this script
},
{
type: "spline",
dataPoints: [{ x: 1, y: 450 },{ x: 2, y: 414}]
}
],
});
chart.render();
// canvas graph ends here
//console.log(sthtml);
}
})
})();
});
【问题讨论】:
-
sthtml有什么数据???
-
@Dinesh 响应 json 数据为 { x: 1, y: 450 },{ x: 2, y: 414} 相似类型
-
@Dinesh 感谢您的回答。我认为这是正确的方法,因为我现在没有收到错误,但是 json 正在被网格化,所以图表没有显示。控制台日志显示这样的数据 ["{ x: 3, y: 33.6 },", "{ x: 4, y: 62.2 },", "{ x: 5, y: 121.2 },", "", x: 0] 我不知道“,”是怎么来的,我的 json 输出只是 { x: 3, y: 33.6 } 这样。我已经更改了我的 json 并删除了,所以 jquery 将添加逗号,但我怎样才能避免 [ 和 "
-
你控制服务器端代码吗? json格式很不对。
-
@Dinesh 我控制服务器端代码,但这是根据 canvasjs 数据格式的要求
标签: javascript jquery ajax twitter-bootstrap canvasjs