D3.js:显示有限的刻度 [英] D3.js: display limited number of ticks
问题描述
我正在尝试使用d3.ticks
. 根据文档,我应该可以限制数量轴上显示的刻度线数.
I'm trying to use d3.ticks
. According to the documentation, I should be able to restrict the number of ticks displayed on the axis.
但是,这似乎完全没有限制滴答声的数量:
However, this doesn't seem to restrict the number of ticks at all:
xAxis = d3.svg.axis().scale(xScale).orient("bottom").ticks(2)
是因为我的体重秤是顺序的吗?
Is it because my scale is ordinal?
JSFiddle此处: http://jsfiddle.net/samselikoff/9tfD2/1/
JSFiddle here: http://jsfiddle.net/samselikoff/9tfD2/1/
推荐答案
axis.ticks
仅在基础比例尺实现ticks
函数时有效,而序数比例尺则不能.默认情况下,序数刻度的轴刻度包含刻度的域,但是您可以通过提供 axis.tickValues .
axis.ticks
only works when the underlying scale implements a ticks
function, which ordinal scales do not. By default, the axis ticks for an ordinal scale are comprised of the scale's domain, but you can override this by supplying explicit tick values with axis.tickValues.
这篇关于D3.js:显示有限的刻度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!