How to set the domain and scale on an yaxis on a discreteBarChart nvd3.js

前端 未结 3 602
我寻月下人不归
我寻月下人不归 2021-01-18 11:47

I\'m using d3.js charts in one of my applications. Here they are in this image See Charts

For Y axis on Money chart (See in the Image), I want maximum value rounded

相关标签:
3条回答
  • 2021-01-18 12:19

    I use nvd3 and for me this worked instead:

    nv.models.discreteBarChart().yDomain([0,400])
    

    I could'nt get it to work with yScale.domain

    0 讨论(0)
  • 2021-01-18 12:22

    You need to modify the domain of the Y-axis scale. Usually it is derived from the maximum value of the data with a statement like the following:

    yScale.domain([0, d3.max(data, function (d) { return d.v; }) ]);
    

    In your case, you should modify it to be more like this instead:

    yScale.domain([0, 400]);
    

    Alternatively, if you want to set the maximum value from the data or a minimum static value, you could do something like the following:

    yScale.domain([0, d3.max(data, function (d) { return d.v > 400 ? d.v : 400; }) ]);
    

    A full example jsfiddle is here.

    That's how to do it with D3.js, I'm not familiar with the venerable nvd3.js lib, so I'm not sure how to access the scale, but i'll take a look and see if I can find it.

    0 讨论(0)
  • 2021-01-18 12:28

    Force Y

    List of numbers to Force into the Y scale (ie. 0, or a max / min, etc.). The numbers tell the d3.js the values to use in the scale, rather than d3.js determining the values.

    Datatype: Array of Numbers (i.e. [0, 50]

    http://cmaurer.github.io/angularjs-nvd3-directives/line.chart.html

    0 讨论(0)
提交回复
热议问题