Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change range for one y axis nvd3/d3

I am currently using the multiChart model and I have two different y Axes. I would like to like to change both of the axes so that they start at 0 because currently they start at the smallest y data point.

I have tried doing the following

chart.yAxis1
tickFormat(d3.format(',.f'))
.domain([0,max_y]);

but that doesnt seem to work

and

.forceY ([0, max_y])

it tells me that there is no forceY function

Any ideas?

like image 351
Siva Avatar asked Jun 12 '13 16:06

Siva


2 Answers

You can force min and max values in NVD3 for line or bar charts, try as below:

chart.bars.forceY([0]);

chart.lines.forceY([0,100]);
like image 172
Varun Avatar answered Nov 10 '22 04:11

Varun


.domain([0, max_y]) should be used on a scale object, not an axis object.

So:

var yScale = d3.scale.linear().domain([0,max_y])
var yAxis  = d3.svg.axis().scale(yScale)

This should work; if not, you should post what you have as a jsfiddle.

like image 41
Adam Pearce Avatar answered Nov 10 '22 03:11

Adam Pearce