我已经script标签内的下列D3代码代替:使用D3读取CSV返回html的CSV数据
d3.csv("data.csv", function(error, data) {
data.forEach(function(d) {
console.log(data[0]);
d.date = parseDate(d.date);
d.close = +d.close;
});
console.log("hello2")
// Scale the range of the data
x.domain(d3.extent(data, function(d) { return d.date; }));
y.domain([0, d3.max(data, function(d) { return d.close; })]);
svg.append("path") // Add the valueline path.
.attr("class", "line")
.attr("d", valueline(data));
svg.append("g") // Add the X Axis
.attr("class", "x axis")
.attr("transform", "translate(0," + height + ")")
.call(xAxis);
svg.append("g") // Add the Y Axis
.attr("class", "y axis")
.call(yAxis);
});
当我在浏览器中查看控制台输出为console.log
是Object {<!DOCTYPE html>: "</head>"}
。我预计输出为{"date": "1-May-12", close: "58.13"}
。
为什么使用我的html作为数据参数而不是我的CSV数据的回调函数?请注意,我也运行一个简单的节点服务器,以便我可以读取CSV。
也粘贴你的data.csv – Cyril
https://github.com/mbostock/d3/wiki/CSV#csv >如果发生错误,回调函数将被调用null。 功能(错误,数据) - >功能(数据)请。 –
'日期,结束 1 - 5月份,12,58.13 30-APR-12,53.98 27-APR-12,67.00 26-APR-12,89.70 25-APR-12,99.00' 那是什么在我的CSV @Cyril – PC3SQ