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

前端 未结 3 605
我寻月下人不归
我寻月下人不归 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: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.

提交回复
热议问题