.ticks()运作需要什么? [英] What does it take for .ticks() to work?

查看:110
本文介绍了.ticks()运作需要什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

.ticks()似乎不适用于我的条形图.有人可以看看吗?

这是小提琴.我在对象起点附近的x轴上设置了刻度:

xAxis = d3.svg.axis().scale(xScale).orient("bottom").ticks(3),

解决方案

我的信誉不足,无法在第一篇文章中添加评论,但我认为存在误解.

轴上的标签必须为2、5或10的倍数.ticks函数可以采用任何数字,但是它将修改该数字以确保轴为2、5或10的倍数./p>

例如,如果域是0-100,并且您想要4个滴答声(0、33.33、66.66、100),它将舍入到6,以为您提供漂亮"的数字(0、20、40、60、80 ,100).但是,如果将ticks设置为3,将很荣幸这样做,您将获得0、50和100.

此处的一则帖子中有Mike对这种行为的解释.

我仍然不清楚,如果将刻度设置为5,为什么它不算为0、25、50、75、100,但是我想我至少要消除一些困惑.

.ticks() doesn't seem to be working on my bar chart. Can somebody take a look?

Here's the fiddle. I set ticks on the x-axis near the beginning of the object:

xAxis = d3.svg.axis().scale(xScale).orient("bottom").ticks(3),

解决方案

I don't have enough reputation to add a comment to that first post but I think there is a misunderstanding.

The labels on the axis must be a multiple of 2, 5, or 10. The ticks function can take any number but it will modify that number to make sure the axis is a multiple of 2, 5, or 10.

For example, if the domain is 0-100 and you want 4 ticks (0, 33.33, 66.66, 100) it will round up to 6 to give you "pretty" numbers (0, 20, 40, 60, 80, 100). However, if you set ticks to 3 it will honor that and you'll have 0, 50, and 100.

Here's a post with Mike's explanation of this behavior.

It is still unclear to me why it won't count 0, 25, 50, 75, 100 if you set the ticks to 5 but I thought I'd try to clear up at least some of the confusion.

这篇关于.ticks()运作需要什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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