Re: Is it possible to format the percentage in the pie chart to 2 decimal places instead of one?

20,958 views
Skip to first unread message

asgallant

unread,
Dec 13, 2012, 2:35:02 PM12/13/12
to google-visua...@googlegroups.com
You can format the data displayed in the tooltips to 2 decimal places, but not the slice labels.  To format the tooltips, use a NumberFormatter on the data column in the DataTable.

On Thursday, December 13, 2012 1:41:12 PM UTC-5, Kwasi wrote:
Is it possible to format the percentage in the pie chart to 2 decimal places instead of one?

Kwasi

unread,
Dec 14, 2012, 12:03:35 PM12/14/12
to google-visua...@googlegroups.com
Thanks asgallant ,
But I'm calling the labels and values from a database straight into the data.colum without generating a table. IS it possible to format the values in my case?

asgallant

unread,
Dec 14, 2012, 12:14:59 PM12/14/12
to google-visua...@googlegroups.com
I'll have to take a look at your code so I can see what it is you're doing before I can give a yes or no.

Mahmoud Said

unread,
May 21, 2014, 8:01:49 AM5/21/14
to google-visua...@googlegroups.com
Did u reach Any solution or workaround?. i'm stuck with the same problem here, I need to display 2 digits after the the decimal point in the percentage. apparently the use of fractionDigits does not help



function drawChart(data) {
  var data = google.visualization.arrayToDataTable([
                ['choice', 'sum'],
                ['option1', data.total_val1],
                ['option2', data.total_val2]
              ]);
  
  var options = {
    title: data.title, 
    is3D: true, 
    colors:['#CB5758','#4F8DD6'],
    width:600,
    height:400,
    fontSize: 18,
    chartArea: {width: '80%'}
  };

  var formatter = new google.visualization.NumberFormat({pattern:'###,###', fractionDigits: 2} );
  formatter.format(data, 1);
  
  var chart = new google.visualization.PieChart(document.getElementById('chart_div'));
  chart.draw(data, options);  
}

Daniel LaLiberte

unread,
May 21, 2014, 8:32:22 AM5/21/14
to google-visua...@googlegroups.com
Mohmoud,

You have conflicting format options.  As the docs about the pattern option say: "When provided, all other options are ignored, except negativeColor."
So your fractionDigits option is ignored.  But you can get the equivalent of two decimal digits as part of your pattern by using:  pattern: '###,###.00'.

dan


--
You received this message because you are subscribed to the Google Groups "Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-visualizati...@googlegroups.com.

To post to this group, send email to google-visua...@googlegroups.com.
Visit this group at http://groups.google.com/group/google-visualization-api.
For more options, visit https://groups.google.com/d/optout.



--
dlaliberte@Google.com   5CC, Cambridge MA
daniel.laliberte@GMail.com 9 Juniper Ridge Road, Acton MA

Mahmoud Said

unread,
May 21, 2014, 8:44:12 AM5/21/14
to google-visua...@googlegroups.com
Thank you Daniel, you are right, i tried it. but i realized that both affect the format of the displayed value,   what I need it the "percentage"

for examples

the values are 7777  and 3333

The percentage should be 77.77  and 33.33  , however, the pie chard displays it as  77.8 and 33.2
I need to display more fraction digits in the "percentage" part


--
You received this message because you are subscribed to a topic in the Google Groups "Google Visualization API" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-visualization-api/vCNW1Fdva5o/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-visualizati...@googlegroups.com.

To post to this group, send email to google-visua...@googlegroups.com.
Visit this group at http://groups.google.com/group/google-visualization-api.
For more options, visit https://groups.google.com/d/optout.



--
Mahmoud Said
Software Engineer - eSpace

Daniel LaLiberte

unread,
May 21, 2014, 9:41:56 AM5/21/14
to google-visua...@googlegroups.com
Ah, I should have noticed that you mentioned the percentage value.  There is no way at this time to specify the format of the percentage value, though I can see it might be useful in some cases.  We'll consider it for a feature enhancement.

Dan C

unread,
Jul 29, 2015, 3:51:06 PM7/29/15
to Google Visualization API, dlali...@google.com
Hi Daniel,

When will this feature become available? I tried to explain to the business that when % values are rounded up/down, there is no way it will add up to 100%. Might be +/- 0.1%. However, if we can make it 2 decimal or 3 decimal places, then the total should be a lot closer to 100%. Also, is there a function that will expose the value of the % inside the legend?

What rounding method is used for the pie chart?

Thanks!



--
dlali...@Google.com   5CC, Cambridge MA
daniel.l...@GMail.com 9 Juniper Ridge Road, Acton MA

--
You received this message because you are subscribed to a topic in the Google Groups "Google Visualization API" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-visualization-api/vCNW1Fdva5o/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-visualizati...@googlegroups.com.

To post to this group, send email to google-visua...@googlegroups.com.
Visit this group at http://groups.google.com/group/google-visualization-api.
For more options, visit https://groups.google.com/d/optout.



--
Mahmoud Said
Software Engineer - eSpace

--
You received this message because you are subscribed to the Google Groups "Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-visualizati...@googlegroups.com.
To post to this group, send email to google-visua...@googlegroups.com.
Visit this group at http://groups.google.com/group/google-visualization-api.
For more options, visit https://groups.google.com/d/optout.



--
dlali...@Google.com   5CC, Cambridge MA
daniel.l...@GMail.com 9 Juniper Ridge Road, Acton MA

Daniel LaLiberte

unread,
Jul 30, 2015, 10:37:31 PM7/30/15
to Dan C, Google Visualization API
We haven't worked on this yet.  (I've been focused on getting the frozen version 41 out, which it now is, so we'll be moving on to other issues.)

Showing more digits of the percentage should help with adding up all of the slices closer to 100%.  There is no way to get that value out now, though we'll keep that in mind for the future.

Here is how the percentage value is calculated now, using the JavaScript Math.round function:
Math.round(relativeValue * 1000) / 10 + '%'
dlaliberte@Google.com   5CC, Cambridge MA
daniel.laliberte@GMail.com 9 Juniper Ridge Road, Acton MA

spenc...@pwc.com

unread,
Sep 4, 2015, 1:44:16 PM9/4/15
to Google Visualization API, dan.cu...@gmail.com
Please make this flexible so any number of decimal points are supported, either specifically or though a format string.  In my case, I wanted to have zero decimal places.

Thanks,
Spencer
To unsubscribe from this group and stop receiving emails from it, send an email to google-visualization-api+unsub...@googlegroups.com.

To post to this group, send email to google-visua...@googlegroups.com.
Visit this group at http://groups.google.com/group/google-visualization-api.
For more options, visit https://groups.google.com/d/optout.



--
dlali...@Google.com   5CC, Cambridge MA
daniel.l...@GMail.com 9 Juniper Ridge Road, Acton MA

--
You received this message because you are subscribed to a topic in the Google Groups "Google Visualization API" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-visualization-api/vCNW1Fdva5o/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-visualization-api+unsub...@googlegroups.com.

To post to this group, send email to google-visua...@googlegroups.com.
Visit this group at http://groups.google.com/group/google-visualization-api.
For more options, visit https://groups.google.com/d/optout.



--
Mahmoud Said
Software Engineer - eSpace

--
You received this message because you are subscribed to the Google Groups "Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-visualization-api+unsub...@googlegroups.com.
To post to this group, send email to google-visua...@googlegroups.com.
Visit this group at http://groups.google.com/group/google-visualization-api.
For more options, visit https://groups.google.com/d/optout.



--
dlali...@Google.com   5CC, Cambridge MA
daniel.l...@GMail.com 9 Juniper Ridge Road, Acton MA

Beth

unread,
Mar 16, 2016, 1:34:56 PM3/16/16
to Google Visualization API, dan.cu...@gmail.com, Jan Quarles
I too am trying to display the fractions on my pie chart without the added decimal place. Any progress on this? Thanks.
Message has been deleted

Shabir Ahmed

unread,
Apr 19, 2016, 2:31:52 PM4/19/16
to Google Visualization API
do we have any update on this issue, did any find a way to present more digit with percentage?
To unsubscribe from this group and stop receiving emails from it, send an email to google-visualization-api+unsub...@googlegroups.com.

To post to this group, send email to google-visua...@googlegroups.com.
Visit this group at http://groups.google.com/group/google-visualization-api.
For more options, visit https://groups.google.com/d/optout.



--
dlali...@Google.com   5CC, Cambridge MA
daniel.l...@GMail.com 9 Juniper Ridge Road, Acton MA

--
You received this message because you are subscribed to a topic in the Google Groups "Google Visualization API" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-visualization-api/vCNW1Fdva5o/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-visualization-api+unsub...@googlegroups.com.

To post to this group, send email to google-visua...@googlegroups.com.
Visit this group at http://groups.google.com/group/google-visualization-api.
For more options, visit https://groups.google.com/d/optout.



--
Mahmoud Said
Software Engineer - eSpace

--
You received this message because you are subscribed to the Google Groups "Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-visualization-api+unsub...@googlegroups.com.

To post to this group, send email to google-visua...@googlegroups.com.
Visit this group at http://groups.google.com/group/google-visualization-api.
For more options, visit https://groups.google.com/d/optout.



--
dlali...@Google.com   5CC, Cambridge MA
daniel.l...@GMail.com 9 Juniper Ridge Road, Acton MA

slavko...@wonderlab-it.co.uk

unread,
May 7, 2016, 6:25:06 AM5/7/16
to Google Visualization API
Hi all,

I on the other hand have an opposite requirement -  not to show any decimals as this clutters the graph. This should be configurable, I can't see how this can be that big of a deal to implement so it has to wait for over three years...
The more I use chart libraries, the more I think it would be better just to start drawing SVGs manually...

slavko...@wonderlab-it.co.uk

unread,
May 7, 2016, 6:30:09 AM5/7/16
to Google Visualization API
Ok, found a way around this - feed the graph with pre-calculated integers that add up to 100 and it will show without decimals!

Doug Marinaro

unread,
Jan 17, 2017, 12:02:36 AM1/17/17
to Google Visualization API, slavko...@wonderlab-it.co.uk
Great idea. You can get the same effect by using the ROUND function to two places in the field where the percentage is calculated.

KADlancer

unread,
Apr 27, 2017, 7:59:13 AM4/27/17
to Google Visualization API
I would love an update on this too... I am looking for a way to force the first decimal to show, even for zero values like 8,0%.

I'm using the "labeled" option for my Ring/Pie Charts and I would like to change the formatting of the calculated percentage that is shown below the line of each Pie Chart Slice Label.

Interspock

unread,
Oct 12, 2017, 9:33:37 PM10/12/17
to Google Visualization API
Same problem as KADlancer, labeled option for Pie Charts, shows one-decimal percentage. 
I prefer to show *no percentage at all* in labeled legend connected with the line to the slice.. but I guess that it's not possible...

Miguel González

unread,
May 14, 2018, 9:00:10 AM5/14/18
to Google Visualization API
If I want to do this but, with amcharts, how do I do it?

Tristan Bailey

unread,
Aug 8, 2019, 4:23:53 PM8/8/19
to Google Visualization API

Have this problem, and a solution for this in the short term.

POSSIBLE SOLUTION:
use the label which is text string, if you do not need a key and can put text needed in a tooltip per slice.

options add:
pieSliceText: 'label',

Then for your label column put '35.77%' the percentage you want. 
Reply all
Reply to author
Forward
0 new messages