简体   繁体   English

D3.js折线图,Y轴上的相对最小值和最大值

[英]D3.js Line chart with relative min and max in Y axis

Consider the following VND3 line graph: http://jsfiddle.net/tramtom/hfv68yan/ 考虑以下VND3折线图: http : //jsfiddle.net/tramtom/hfv68yan/

The graph plots the line ok, however most of my data is the static over long periods, and the two series will always have one at the top of the graphic and other on the bottom axis. 该图绘制了ok线,但是我的大部分数据在很长一段时间内都是静态的,并且两个系列始终在图形的顶部具有一个,而在底轴上则具有另一个。

How to create relative minimum and maximums for the Y axis in a way that lines for the series be almost in the middle or at least spaced so that the lower valued series does not lie almost entirely on the x-axis. 如何以一系列的直线几乎在中间或至少间隔开的方式为Y轴创建相对的最大值和最小值,以使价值较低的序列几乎不完全位于x轴上。

Need to add 100 units below the minimum and 100 units above the maximum so the lines don't be at the top or bottom of the graphic. 需要在最小值下方添加100个单位,在最大值上方添加100个单位,以使这些行不在图形的顶部或底部。

I tried setting a domain and range values like in here http://jsfiddle.net/tramtom/hfv68yan/1/ but have no effect 我尝试在此处http://jsfiddle.net/tramtom/hfv68yan/1/中设置域和范围值,但没有效果

var yScale = d3.scale.linear()
.domain([
     d3.min(data, function (d) {
         return d.y;
     }) - 100,
     d3.max(data, function (d) {
         return d.y;
     }) + 100
])
.range([
     d3.min(data, function (d) {
         return d.y;
     }),
     d3.max(data, function (d) {
         return d.y;
     })
]);

You need to force the axis range by adding .forceY([0,500]) to the chart instantiation. 您需要通过将.forceY([0,500])到图表实例中来强制轴范围。

This SO answer might be helpful. 这样的答案可能会有所帮助。 That should at least point you in the right direction. 那至少应该为您指明正确的方向。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM