本文介绍了d3js:时间缩放和"1901"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用基于时间的散点图,并且所使用的数据仅按月,时和日解析时间.在轴标签上,我得到"1901". D3似乎正在选择一年并显示它.我如何轻松摆脱这种情况?我不想显示任何年份:

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". D3 seems to be choosing a year and displaying it. How can I easily get rid of this? I don't want any year displayed:

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

推荐答案

,您需要设置 tickFormat 轴,仅显示月份和日期. tickFormat接收一个带有日期并返回字符串的函数.您可以使用 d3.time.format 设置刻度格式:

you need to set the tickFormat of your axis to display only months and days. The tickFormat receives a function that takes a date and returns a string. You can use d3.time.format to set the tick format:

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

此致

这篇关于d3js:时间缩放和"1901"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-10 11:42