简体   繁体   English

d3js:时间缩放和“1901”

[英]d3js: time scaling and "1901"

I'm working with a time-based scatterplot and am using data which only parses times by month, hour and day.我正在使用基于时间的散点图,并且正在使用仅按月、小时和日解析时间的数据。 On my axis labels, I'm getting "1901".在我的轴标签上,我得到了“1901”。 D3 seems to be choosing a year and displaying it. D3 似乎在选择一年并显示它。 How can I easily get rid of this?我怎样才能轻松摆脱这个? I don't want any year displayed:我不想显示任何年份:

1901 example http://lmnts.lmnarchitects.com/wp-content/uploads/2014/04/2014-04-01-09_31_30-127.0.0.1_8020_Climate3_seattle-winter-temps.html.jpg 1901 示例 http://lmnts.lmnarchitects.com/wp-content/uploads/2014/04/2014-04-01-09_31_30-127.0.0.1_8020_Climate3_seattle-winter-temps.html.jpg

you need to set the tickFormat of your axis to display only months and days.您需要将轴的tickFormat设置为仅显示月和日。 The tickFormat receives a function that takes a date and returns a string. tickFormat接收一个函数,该函数接受一个日期并返回一个字符串。 You can use d3.time.format to set the tick format:您可以使用d3.time.format设置刻度格式:

var axis = d3.svg.axis()
    // ... set more attributes
    .tickFormat(d3.time.format('%b %d'));  // Abbreviated month and decimal day (Apr 01)

Regards,问候,

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM