I have the following d3 code within script tags:
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);
});
When I check the console in my browser, the output for the console.log
was Object {<!DOCTYPE html>: "</head>"}
. I'm expected the output to be {"date": "1-May-12", close: "58.13"}
.
Why is the callback function using my html as the data parameter rather than my CSV data? Note that I am also running a simple node server so I can read the CSV.