0

I plot very simple data from a JSON file: I need help format my x-date-axis. I don't know how to specify the date format from the JSON-File for d3.js. I tried the following:

var parseDate = d3.time.format("%Y%m%d").parse;

The JSON data looks like this:

var data = [
{"mytime": 20150801, "tt": 17.0}, 
{"mytime": 20150802, "tt": 17.6},
];

The result on the x-axis is not as expected. Find my fiddle here: https://jsfiddle.net/1m1qm6pv/1/

Problem i think is this:

data.forEach(function(d) {
  d.mytime = parseDate(d.mytime);
});

With these 3 lines of code it doesn't work.

1 Answer 1

1

Your "dates" are numbers and hence cannot be parsed into Date objects. To parse them, use strings instead of numbers:

var data = [
  {"mytime": "20150801", "tt": 17.0}, 
  {"mytime": "20150802", "tt": 17.6},
];

Complete demo here.

Sign up to request clarification or add additional context in comments.

3 Comments

How would you connect line between points in your demo, to make it appear continuous?
Thanks!, It worked,Trying to add a data legend to the line it's not working. when added attribute like this: .attr("data-legend","city") .attr('stroke', 'green')
I have pasted my complete problem here: stackoverflow.com/questions/36086656/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.