1

Consider the following VND3 line graph: 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.

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.

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.

I tried setting a domain and range values like in here http://jsfiddle.net/tramtom/hfv68yan/1/ but have no effect

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;
     })
]);
edteke
  • 562
  • 5
  • 22
  • possible duplicate of [d3.js & nvd3.js -- How to set y-axis range](http://stackoverflow.com/questions/11766879/d3-js-nvd3-js-how-to-set-y-axis-range) – shabeer90 Aug 29 '14 at 07:27

1 Answers1

1

You need to force the axis range by adding .forceY([0,500]) to the chart instantiation.

This SO answer might be helpful. That should at least point you in the right direction.

Community
  • 1
  • 1
benjaminjosephw
  • 4,369
  • 3
  • 21
  • 40
  • Using '.forceY()' makes the Y axis "static" and when you add or remove series by clicking on the legend, the chart don't animate and adjust the Y axis to reflect the current series max and min. I'm looking for a way to keep the chart the same behavior, just add certain amount of units to the max and min of the current series. – edteke Aug 29 '14 at 13:57
  • I didn't think .forceX() or .forceY() were working, then I noticed in this answer that you need to put your range in an array, and pass that to the method. – sean.boyer Mar 03 '15 at 15:12