d3时间格式x轴显示相同的值

时间:2014-10-30 12:24:49

标签: javascript d3.js

我正在尝试沿d3.js图的x轴绘制日期。但是,当应该有不同的值时,我会沿着a轴重复相同的值。

我按如下方式格式化日期:

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

enter image description here

如下图所示,沿x轴绘制相同的值。

我这样做的方法是否正确?

1 个答案:

答案 0 :(得分:1)

感谢Lars Kotthoff的帮助 谁指出我使用的是古老版本的d3。只需更改为更新版本的d3即可解决我的问题。他通过聊天回答了这个问题,因此没有直接的答案来标记为正确的答案。但他解决了这个问题。