简体   繁体   English

D3js更改可缩放时间轴上的刻度

[英]D3js Changing ticks on Zoomable Time axis

Background 背景

I have a zoomable time graph which I build incorporating the following code: 我有一个包含以下代码的可缩放时间图:

var x = d3.time.scale().range([0, 100]);
var xAxis = d3.svg.axis()
    .scale(x)
    .tickFormat(customformatter);

When the appropriate interval is years, it shows ticks of years. 当适当的时间间隔是年时,它会显示年的滴答声。 Months shows months, etc. 月份显示月份等。

Problem 问题

This works wonderfully, generating great ticks until I zoom down into weeks, at which point I need to be able to dictate what day of the week ticks show for (Sunday, monday, etc.). 这非常好,可以产生很大的滴答声,直到我缩小到几周为止,这时我需要能够决定星期几在哪一天显示(星期日,星期一等)。 I am aware of the multiformat custom generator for tickFormat in which you can specify the format given the appropriate interval. 我知道tickFormat的多格式自定义生成器,您可以在其中指定给定适当间隔的格式。 That will not change the ticks, however. 但是,那不会改变刻度线。 Is there a way to set the start of the weeks' rules while maintaining the tick generation that otherwise exists at the year, month, day (etc.) level? 有没有办法设置周规则的开始时间,同时又保持年,月,日(等)级别存在的滴答生成? Can the default start date be set to some other day of the week for the d3 library? 可以将d3库的默认开始日期设置为星期几吗?


This is hardly a recommendable answer to my own question, but if anyone is desperate one way is to override the source code in /src/time/week.js: 对于我自己的问题,这几乎不是推荐的答案,但是如果有人不顾一切,一种方法是覆盖/src/time/week.js中的源代码:

d3_time.week = d3_time.sunday;
d3_time.weeks = d3_time.sunday.range;
d3_time.weeks.utc = d3_time.sunday.utc.range;
d3_time.weekOfYear = d3_time.sundayOfYear;

Just swap out 'sunday' for another day of the week. 只需将“星期日”换成一周的另一天。

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

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