D3.js:显示有限数量的滴答声 [英] D3.js: display limited number of ticks

查看:26
本文介绍了D3.js:显示有限数量的滴答声的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 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 仅在底层 scale 实现了 ticks 函数时才有效,而序数 scales 没有.默认情况下,序数刻度的轴刻度由刻度的域组成,但您可以通过使用 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆