d3.js &nvd3.js -- 如何设置y轴范围 [英] d3.js & nvd3.js -- How to set y-axis range
问题描述
我正在尝试将图表的 y 轴范围设置为 1-100.
I'm trying to set the y-axis range of the chart from 1-100.
查阅了 API 文档,找到了一个使用axis.tickValues 的可能解决方案,如下所示https://github.com/mbostock/d3/wiki/SVG-Axes#wiki-tickValues
Consulted the API documentation and found a possible solution with axis.tickValues as seen here https://github.com/mbostock/d3/wiki/SVG-Axes#wiki-tickValues
但是,使用该选项不起作用.在axis.tickSize下链接的文档页面上进一步阅读,发现了以下行
However, using the option does not work. Reading further down on the documentation page linked above under axis.tickSize, the following line was spotted
结束刻度由关联的尺度的域范围决定,并且是生成的路径域的一部分而不是刻度线
The end ticks are determined by the associated scale's domain extent, and are part of the generated path domain rather than a tick line
所以我认为设置范围的最小值和最大值不能通过轴选项来完成.
So I take it setting the min and max of the range can't be done through the Axis option.
关于在哪里可以指定范围的任何想法?
Any ideas on where I can specify the range?
推荐答案
找到了解决方案.
将 .forceY([0,100])
附加到图表的实例会强制轴采用数组中指定的范围.
Appending .forceY([0,100])
to the instantiation of the chart forces the axis to take on the range specified in the array.
从这里的例子 http://nvd3.org/livecode/#codemirrorNav
将 .forceY([0,100])
附加到图表变量有效.
Appending .forceY([0,100])
to the chart variable works.
这篇关于d3.js &nvd3.js -- 如何设置y轴范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!