我正在尝试绘制一些时间序列数据使用MetricsGraphics.js ,但似乎无法让它发挥作用,而且我在网上找不到答案。 Metrics 构建在 D3.js 之上
错误是:
TypeError: Cannot read property '0' of undefined
at process_line (http://localhost:9000/bower_components/metrics-graphics/dist/metricsgraphics.js:4211:50)
at Object.charts.line.init (http://localhost:9000/bower_components/metrics-graphics/dist/metricsgraphics.js:2333:13)
at Object.charts.line (http://localhost:9000/bower_components/metrics-graphics/dist/metricsgraphics.js:2973:14)
at Object.MG.data_graphic (http://localhost:9000/bower_components/metrics-graphics/dist/metricsgraphics.js:216:20)
at init (http://localhost:9000/pages/home/home-controller.js:46:12)
at new <anonymous> (http://localhost:9000/pages/home/home-controller.js:59:5)
at invoke (http://localhost:9000/bower_components/angular/angular.js:4182:17)
at Object.instantiate (http://localhost:9000/bower_components/angular/angular.js:4190:27)
at http://localhost:9000/bower_components/angular/angular.js:8453:28
at link (http://localhost:9000/bower_components/angular-route/angular-route.js:981:26) <div class="container ng-scope" ng-view="">
这是创建图表对象的代码:
MG.data_graphic({
title: "Projector Usage",
description: "Projector Usage in Folsom.",
data: chartData,
width: 800,
height: 450,
target: "#chart",
x_accessor: "date",
y_accessor: "value"
});
这段代码正在生成 JSON 对象数组:
for(var x=0; x < data.length; x++){
chartData.push({
date : new Date(data[x]['timestamp']),
value : data[x]['result']['projectorsOn']
})
}
最佳答案
所以......这是一个愚蠢的错误。在我调用填充对象的异步数据调用之前,MG.data_graphics 试图访问图表数据。
为了解决这个问题,我刚刚将该函数添加到 $http.post().success() 回调中。
关于javascript - 使用 Metrics Graphics.js 时出现 TypeError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28201934/