问题
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?
回答1:
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]);
回答2:
.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.
回答3:
The only way I found that solves the problem is by adding yDomain1 or yDomain2 in the chart definition
For nvd3:
var chart = nv.models.multiChart()
.yDomain1([-20, 80])
.yDomain2([-50, 200])
For nvd3 AngularJS:
$scope.dashOptions = {
chart : {
type : 'multiChart',
yDomain1:[-20, 80],
yDomain2:[-50, 100],
Source: Solution by Alex. in another post
来源:https://stackoverflow.com/questions/17070238/change-range-for-one-y-axis-nvd3-d3