score:1

Accepted answer

What you're missing is the parsing of the data from text to the right format, using function type (which in turn calls the date parser function). Just insert the following line:

data.forEach(type);

About the line axis, you need to revert to the original code (which doesn't have to change for you):

var line = d3.svg.line()
    .interpolate("monotone")
    .x(function(d) { return x(d.date); })
    .y(function(d) { return y(d.price); });

d.date is your original data, x(d.date) translates this into an x-coordinate for the drawing, and the block above tells that the data should use the x and y functions to generate the coordinates. at this point, the data doesn't have to be taken into account.

https://jsfiddle.net/2d042rnL/


I general, to use local data instead of an external file, look for the line as this one:

d3.csv("readme.csv", type, function(error, data) {
  ...
}

and you need to apply the same preprocessing to your data (here, the type function), and then call the function. What I usualy do is the following:

process =  function(error, data) {
  ...
}
/* use external file: */
//d3.csv("readme.csv", type, process) 
/* use local data: */
data.forEach(type)
process(false, data)

Related Query