问题
How can I set my domain to [0,400] with nvd3? Here is my code:
var chart;
nv.addGraph(function() {
chart = nv.models.multiBarHorizontalChart().x(function(d) {
return d.label
}).y(function(d) {
return d.value
}).margin({
top : 30,
right : 20,
bottom : 50,
left : 175
}).barColor(d3.scale.category20().range()).transitionDuration(250).stacked(true)
chart.yAxis.tickFormat(d3.format(',.2f'));
d3.select('#chart1 svg').datum(long_short_data).call(chart);
nv.utils.windowResize(chart.update);
chart.dispatch.on('stateChange', function(e) {
nv.log('New State:', JSON.stringify(e));
});
return chart;
});
回答1:
You could use xDomain or yDomain
depending on you axis requirement and finally
chart.xDomain([0,400])
If you want to play around with the ranges on the yAxis you could try
chart.forceY([0, 400]); or chart.forceX([0, 400]);
Hope it helps.
回答2:
Just to add one note that forcing axis values work at the time of chart instantiation. Axis values do not set if I do it after chart instantiation.
来源:https://stackoverflow.com/questions/19048454/nvd3-multi-bar-horizontal-chart-x-axis-domain