如何将d3.svg.axis限制为整数标签? [英] How to limit d3.svg.axis to integer labels?

查看:534
本文介绍了如何将d3.svg.axis限制为整数标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能限制图表上显示的d3.svg.axis整数标签的数量?例如这个图。这里只有5个大小: [0,1,2,3,4] 。但是, .5,1.5,2.5 3.5 还会显示此刻度。



$

$

$

$

$

$ < b
$ b

  d3.svg.axis()
.tickFormat(d3.format(d));

您也可以使用 tickFormat 轴将默认自动使用。


Is there any possibility to limit the number of d3.svg.axis integer labels displayed on the graph? Take for instance this graph. There are only 5 sizes here: [0, 1, 2, 3, 4]. However, the ticks are also displayed for .5, 1.5, 2.5 and 3.5.

解决方案

You should be able to use d3.format instead of writing your own format function for this.

d3.svg.axis()
    .tickFormat(d3.format("d"));

You can also use tickFormat on your scale which the axis will automatically use by default.

这篇关于如何将d3.svg.axis限制为整数标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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