从D3.js轴删除结束刻度 [英] Remove end-ticks from D3.js axis

查看:190
本文介绍了从D3.js轴删除结束刻度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用(优秀的)D3.js生成一些绘图,我找不到一个方法从x和y轴删除结束标记。

I'm using (the excellent) D3.js to generate some plots, and I can't find a way to remove the end ticks from the x and y axis.

以y轴为例。

当结束时间值与标签重合时,我可以确定。

When the end tick value coincides with a label, I'm ok with having it.

但是当最后一个圆形标签低于绘图结束时,我会得到两个tick,一个用于最后一个圆形标签,另一个在y轴末端。

But when the last round label is below the end of the plot, I get two ticks, one for the last rounded label and one above it at the end of the y-axis.

我不想让这个结束标记可见,因为我发现它出现在标签之间的正常反转之间分散注意力。

I don't want this end-tick visible, because I find the fact that it appears in less than the regular inverval between labels distracting.

在这里查看我所描述的例子:

See here for an example of what I'm describing:

http://www.road2stat.com/cn/wp-content/attachments/2012/04/d3_interactive.png a>

任何提示?

PS作为回应建议,我可以明确设置tick。但我喜欢隐式生成ticks的方便,只是不想要不带标签的ticks污染轴。因此,一个理想的解决方案(如果存在)也会考虑。

P.S As a response suggested, I could set the ticks explicitly. But I like the convenience of the implicit generated ticks, just don't want unlabelled ticks to pollute the axis. So an ideal solution (if exists) would also take than into account.

推荐答案

axis.tick * 功能可以帮助您。你有一些可能性,以防止你描述的行为。您可以使用 tickValues()函数显式设置记号。或者,您可以使用 tickSize()将结束标记的大小设置为0。您还可以使用 ticks()函数控制底层刻度。

The axis.tick* functions can help you there. You have a number of possibilities to prevent the behaviour you're describing. You could set the ticks explicitly using the tickValues() function. Or you could set the size of the end ticks to 0 using tickSize(). You can also control the underlying scale using the ticks() function.

根据您的特定场景,这些选项可能比其他选项更有意义。

Depending on your particular scenario, one of these options may make more sense than the others.

这篇关于从D3.js轴删除结束刻度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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