d3.js-开始和结束刻度 [英] d3.js - starting and ending tick

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

问题描述

我正在d3.js中构建面积图.

I am building an area graph in d3.js.

对于我的y轴,我想使用线性刻度,该刻度从图形中表示的数据的最小值延伸到最大值.

For my y axis, I want to use a linear scale that extends from the minimal value to the maximal value of the data represented in the graph.

使用

y = d3.scale.linear().range([height, 0]),
yAxis = d3.svg.axis().scale(y).orient("left")

d3仅显示10000的倍数的刻度线.

d3 shows ticks only for multiples of 10000.

我还希望看到起始值和结束值的刻度.这可能吗?怎么样?

I would like also to see ticks for the starting and the ending value. Is this possible? How?

推荐答案

一种方法是将比例尺的域扩展为"nice",即包括将出现在轴上的"round"值.您可以通过在设置域后调用.nice()来做到这一点:

One way to do this is to extend the domain of a scale to be "nice", i.e. to include "round" values that will show up on the axis. You can do this by calling .nice() after setting the domain:

y = d3.scale.linear().range([height, 0]).domain(...).nice();

另一种选择是显式指定刻度线,这通常会更加痛苦.

The alternative would be to specify the ticks explicitly, which is much more painful in general.

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

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