10

Have a little modified version of linePlusBarChart model(), when pass data that has all y values setted to zero Y axis show me a range between 1 and -1. Is possible to set a range between 0 and 1?

Have tried with chart.yAxis.scale().domain([0]); and chart.forceY([0]) but nothing.

4
  • 1
    You need to pass a two-element array to forceY -- stackoverflow.com/questions/11766879/… Mar 4, 2014 at 13:13
  • have tried but nothing, problem still present Mar 4, 2014 at 13:18
  • could you put your code on JSFiddle
    – shabeer90
    Mar 4, 2014 at 15:12
  • I should have said, my issue is with the stackedAreaChart, where apparently yDomain doesn't work as expected.
    – Alnitak
    Sep 9, 2015 at 10:15

2 Answers 2

3

forceY forces the domain to include the values you pass in, it doesn't shrink the domain created from the data. To set a specific domain, you set chart.yDomain([0,1]). However, that would set the domain to [0,1] regardless of what your data is. As I understand it, you only want to change the behaviour when all your y-values are 0.

For that, try chart.forceY([1]). Now, when NVD3 tries to figure out the domain, it will see both the zero values from the data and the 1 from the force statement. So it will have a valid domain and it won't have to make up a domain by adding and subtracting 1 from the data value.

1

If you follow the example provided by the nvd3 site example linePlusBarChart

You can insert one line in the javascript

chart.lines.forceY([0,1]);

Here is the test code

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.