Pio
Pio

Reputation: 4064

NVD3 multi bar horizontal chart x axis domain

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;
}); 

Upvotes: 1

Views: 5964

Answers (2)

Vishal
Vishal

Reputation: 2173

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.

Upvotes: 0

shabeer90
shabeer90

Reputation: 5151

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.

Upvotes: 4

Related Questions