问题
I am trying to plot dates along the x axis of a d3.js graph. However I am getting the same value repeated along the a axis, when there should be different values instead.
I am formatting the date as follows:
var format = d3.time.format('%m/%d/%Y %H:%M').parse;
Then directly after the data call:
data.forEach(function(d) {
d.timestamp = format(d.timestamp); // d.timestamp is from the data
});
Then setting the domain as follows:
var xScale = d3.time.scale().range([0, width]);
xScale.domain([d3.min(data, xValue), d3.max(data, xValue)]);
timestamp location price FirstName LastName
1/6/2014 7:28 Brew've Been Served 11.34 Edvard Vann
1/6/2014 7:34 Hallowed Grounds 52.22 Hideki Cocinaro
1/6/2014 7:35 Brew've Been Served 8.33 Stenig Fusil
1/6/2014 7:36 Hallowed Grounds 16.72 Birgitta Frente
1/6/2014 7:37 Brew've Been Served 4.24 Sven Flecha
1/6/2014 7:38 Brew've Been Served 4.17 Cornelia Lais
1/6/2014 7:42 Coffee Cameleon 28.73 Linnea Bergen
1/6/2014 7:43 Brew've Been Served 9.6 Mat Bramar
1/6/2014 7:43 Brew've Been Served 16.9 Brand Tempestad
1/6/2014 7:47 Hallowed Grounds 16.53 Emile Arpa
1/6/2014 7:48 Hallowed Grounds 10.66 Kare Orilla
1/6/2014 7:49 Coffee Cameleon 8.39 Bertrand Ovan
1/6/2014 7:52 Brew've Been Served 32.83 Hennie Osvaldo
1/6/2014 7:54 Hallowed Grounds 16.88 Nils Calixto
1/6/2014 7:54 Coffee Cameleon 11.86 Adra Nubarron
1/6/2014 7:54 Hallowed Grounds 32.93 Rachel Pantanal
1/6/2014 7:55 Hallowed Grounds 8.05 Lucas Alcazar
1/6/2014 7:55 Brew've Been Served 3.67 Varja Lagos
1/6/2014 7:59 Brew've Been Served 8.88 Inga Ferro
1/6/2014 8:00 Brew've Been Served 4.27 Ruscella Mies Haber
1/6/2014 8:00 Hallowed Grounds 9.69 Anda Ribera
1/6/2014 8:01 Hallowed Grounds 10.07 Lidelse Dedos
1/6/2014 8:06 Brew've Been Served 18.24 Loreto Bodrogi
As you can see in the image below the same value is being plotted along the x axis.
Am I doing this the correct way?
回答1:
Thanks to the help of Lars Kotthoff who pointed out I was using an ancient version of d3. Simply changing to a newer version of d3 solved my issue. He answered this via a chat so there was no direct answer to mark up as the correct one. But he solved the issue.
来源:https://stackoverflow.com/questions/26652925/d3-time-format-x-axis-showing-same-value