0
我想繪製沿d3.js圖的x軸的日期。不過,我得到的是沿a軸重複的相同值,而應該有不同的值。d3時間格式x軸顯示相同的值
我的格式如下日期:數據呼叫後直接
var format = d3.time.format('%m/%d/%Y %H:%M').parse;
然後:
data.forEach(function(d) {
d.timestamp = format(d.timestamp); // d.timestamp is from the data
});
然後設置域如下:
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
正如您在下面的圖片中看到的那樣,沿着x軸繪製了相同的值。
我在做這個正確的方法嗎?
你能發佈完整的代碼和你的數據的例子嗎? – 2014-10-30 13:14:52
請參閱編輯問題 – 2014-10-30 13:25:58
我的猜測是你的數據沒有正確解析,'d.timestamp'只包含日期部分,而不包含時間。 – 2014-10-30 13:30:28