NVD3 multi bar horizontal chart x axis domain
Asked Answered
C

2

1

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;
}); 
Cristophercristy answered 27/9, 2013 at 10:24 Comment(0)
H
4

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.

Heartburn answered 27/9, 2013 at 10:31 Comment(2)
Thanks, I've been trying with xDomain but I was not setting the scale big enough. Then I figured out, that the X axis is the vertical one, not the horizontal one. And I needed to modify the horizontal one .Cristophercristy
@Cristophercristy check if the updated answer with chart.forceX([0, 400]); worksHeartburn
C
0

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.

Clea answered 31/10, 2017 at 15:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.