[Fixed]-Django and d3.tsv, not working

1đź‘Ť

Assuming your tsv file has headers of date and close and that the file download from django is working, then your problem is date parsing.

This line:

var parseTime = d3.timeParse("%d-%b-%y");

is a date like “02-Feb-17”, but you have “2017-02-12 17:51:52.866287”, which is close to:

var parseTime = d3.timeParse("%Y-%m-%d %H:%M:%S.%L");

But this gets a little trickier since JavaScript dates only have millisecond precision, you’ll have to knock off the microseconds:

d3.tsv("someData.tsv", function(d) {
  d.date = parseTime(d.date.substring(0, d.date.length-3)); //<-- parse correctly
  d.close = +d.close;
  return d;
}, function(error, data) {
  ...

Running code here.

👤Mark

Leave a comment