NVD3 multi bar horizontal chart x axis domain

不问归期 提交于 2019-12-23 02:49:09

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!