0

I'm using angular-nvd3 and I need to present some horizontal bars, each with a count and percentage. Problem is that the sum of the percentages is sometimes 101%. For example: example problematic chart There are solutions to the 101% problem - for example substract 1 from one of the percent values if it's 101%. The count can stay the same (so the first bar will be 1 (16%)). But nvd3 works with a function that receives the bar value and needs to return the string that will be presented, which makes it harder to work out a preprocessing solution. Any idea how to make this work?

Jenian
  • 552
  • 1
  • 5
  • 18

1 Answers1

0

I think you could try this:

So you have to store index of current value, because valueFormat does not provide index by it self

var valueFormatIndex = 0;

var data = [{values: [ ... ] }];

var config = {

  ...,

  valueFormat: function(d, index){

    valueFormatIndex = valueFormatIndex + 1;

       // if its a last value we should round to lowest

       if(data[0].values.length == valueFormatIndex) {
          return Math.floor(d)
       }

       return Math.ceil(d) // otherwise return round to top
   },

   ... 

}

JSFiddle example

Leguest
  • 2,097
  • 2
  • 17
  • 20