How to replace percentages with values in a Flotr2 pie chart?

1.3k Views Asked by At

On their site, they have an example of how to draw a pie chart. But it shows percentages of your data instead of the actual values.

I've tried messing with the formatter instance on the pie object, but to no avail. So how does one show values instead of percentages? And more broadly, how does one customize a Flotr2 chart?

2

There are 2 best solutions below

0
On

The label formatter doesn't work in flotr2, it only returns pie & slice, but you can reference the data like the following:

var data = [ { data: [[ 'abc', 3 ]], color: '#FFF' }, 
             { data: [[ 'xyz', 9 ]], color: '#000' } ];

    pie : { show : true, 
            labelFormatter : function (pie, slice) { 
                if (slice < 5) return '';
                else return data[0][0] + ' ' + slice + '%'; },
   other : properties
          }

Only one label will display ('xyz'), since it's over the threshold.

0
On

Here's an example of the pie formatter showing slice values:

pie : {
  show : true, 
  explode : 6,
  labelFormatter : function (pie, slice) {
    return slice;
  }
}

http://jsfiddle.net/cesutherland/vd5gt/4/