Here is a bare-bones pie chart script, useful for decorating a web page with live data from a CGI script. This works in modern browsers that support the CANVAS tag, and avoids loading Java.
Put two lines in the HEAD section of your page like so (the second line is needed to make Microsoft Internet Explorer work):
<script src="piecanvas.js"></script> <!--[if IE]><script src="excanvas.js"></script><![endif]-->
Create a chart like this:
<canvas id="canvas2" width="200" height="220" title="title attribute"> <table id="mydata2" class="datatable"> <caption>Pie Chart using CANVAS</caption> <caption>Tom Van Vleck 2010</caption> <tr><td>Dogs</td><td>25</td></tr> <tr><td>Mice</td><td>2</td><td>#0000ff</td></tr> <tr><td>Cats</td><td>20</td></tr> <tr><td>Rabbits</td><td>15</td></tr> <tr><td>Rats</td><td>2</td></tr> <tr><td>Snakes</td><td>3</td></tr> <tr><td>Horses</td><td>7</td></tr> <tr><td>Hamsters</td><td>5</td></tr> </table> </canvas> <script>piechartcanvas('mydata2','canvas2','#ccffaa', 1);</script>
The arguments to piechartcanvas are the ID tag of the data table, the ID tag of the canvas, an optional background color in hex, rgb(), or as a color name, and an optional flag for the data label format: label format 0 uses the label as specified; label format 1 uses "xx% label". (Each ID tag should be unique in your HTML page.)
(3/18/11: When Microsoft Internet Explorer 9 came out, it didn't display the chart. One way to make it work is to change the DOCTYPE at the top of the file to
.. although this may cause issues with making the code display correctly in older browsers. I also had to make a minor change to piecanvas.js because the CANVAS tag in MSIE 9 works differently from the CANVAS tag in Firefox: in IE9, if there is text inside the CANVAS tag it is displayed after the graphic; in Firefox, text inside the CANVAS tag is treated as "fallback content" and is not displayed if the graphic is rendered. I changed the code for piechartcanvas() to hide the data table if it displayed the chart.)
(6/22/17: Added some code to handle "High DPI" displays. If your display has more than 96 device pixels per inch, the function draws a chart with more pixels and tells the browser to scale it. Tested in Safari, Firefox, and Chrome.)
Here are links to the source files. Feel free to improve on my code.