d3时间格式x轴显示相同的值 [英] d3 time format x axis showing same value
问题描述
我正在尝试沿d3.js图的x轴绘制日期。但是,当应该有不同的值时,我会沿着a轴重复相同的值。
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')。解析;
然后直接在数据调用之后:
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
如下图所示,沿x轴绘制相同的值。
As you can see in the image below the same value is being plotted along the x axis.
我这样做是否正确?
推荐答案
感谢<帮助< a href =https://stackoverflow.com/users/1172002/lars-kotthoff> Lars Kotthoff
谁是pointe我用的是古代版的d3。只需更改为更新版本的d3即可解决我的问题。他通过聊天回答了这个问题,因此没有直接的答案来标记为正确的答案。但他解决了这个问题。
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.
这篇关于d3时间格式x轴显示相同的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!