Home > Articles > Programming infos and tutorials > Google Chart Api – Create a simple pie chart

This pie chart looks better than some dry ratio numbers, isn’t it?

Sample chart

The pie chart above can be created on the fly with this simple piece of html code:

<img src=”http://chart.apis.google.com/chart?
chs=250×100
&amp;chd=t:10,90
&amp;cht=p3
&amp;chl=Smart|Silly”
alt=”Sample chart” />

Interesting here:

1. With http://chart.apis.google.com/chart you call the Google Chart Api

2. This alone gives us of course not yet a nice pie chart – we have to add some parameters

For example with &amp;chd=t:10,90 we get a 10% | 90% ratio of the pie chart.
Means you could manipulate this ratio with some php values. The number of smart people might increase…

<?php
$silly = 5;
$smart = 95;
?>

<img src=”http://chart.apis.google.com/chart?
chs=250×100
&amp;chd=t:<?= $silly ?>,<?= $smart ?>
&amp;cht=p3
&amp;chl=Smart|Silly”
alt=”Sample chart” />

Ideal for web statistics…

3. More information about cool charts with the Google Chart Api you can find here: http://code.google.com/intl/en/apis/chart/types.html#pie_charts

4. And, its also possible to highlight countries on a map

Where is Germany?

Choose the way you would like to be notified for latest posts.

Subscribe to the RSS feed Sign up for Email alerts Follow on Twitter

No Comments yet

Be the first to write a comment

Leave a Comment