d3整数的刻度线 [英] d3 tick marks on integers only

查看:818
本文介绍了d3整数的刻度线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个d3条形图,其值范围从0-3。我想y轴只显示整数值,我可以通过

I have a d3 bar chart whose values range from 0-3. I would like the y-axis to only show integer values, which I can do by

var yAxis = d3.svg.axis().scale(y).orient("right").tickFormat(d3.format("d"));

但是,在非整数标记处仍然有刻度线。设置刻度格式仅隐藏这些标签。我可以明确地设置滴答的数目或滴答的值,但我想做的只是能够指定滴答标记只出现在整数值。这是可能吗?

However, there are still tick marks at the non-integer markings. Setting the tick format only hides those labels. I can explicitly set the number of ticks or the tick values, but what I'd like to do is to just be able to specify that tick marks only appear at integer values. Is that possible?

推荐答案

您可以像下面这样添加.ticks(4)和.tickSubdivide b
$ b

You could add .ticks(4) and .tickSubdivide(0) as I've done below:

var yAxis = d3.svg.axis()
    .scale(y)
    .orient("right")
    .ticks(4)
.tickFormat(d3.format("d"))
    .tickSubdivide(0);

这篇关于d3整数的刻度线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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