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.

byterussian
  • 3,539
  • 6
  • 28
  • 36

2 Answers2

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.

AmeliaBR
  • 27,344
  • 6
  • 86
  • 119
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

card_master
  • 418
  • 3
  • 12