我有以下d3代码:
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数据作为数据参数?请注意,我还运行了一个简单的node服务器,以便可以读取CSV。