Here is a bare-bones pie chart applet, useful for decorating a web page with live data from a CGI script.
Call it like this:
<applet name="Pie" code=Pie.class width=200 height=250 title="applet title"> <param name="charttitle" value="Pie Chart"> <param name="subtitle" value="Tom Van Vleck"> <param name="arg0" value="2,Mice"> <param name="arg1" value="25,Dogs"> <param name="arg2" value="20,Cats"> <param name="arg3" value="15,Rabbits"> <param name="arg4" value="2,Rats"> <param name="arg5" value="3,Snakes"> <param name="arg6" value="7,Horses"> <param name="arg7" value="5,Hamsters"> <param name="bg" value="#bbffaa"> (sorry, Java is not enabled on your browser) </applet>
You can specify the color for the pie wedges by providing a third argument in the "arg" parameters, like so:
<param name="arg0" value="2,Mice,#ff0000">
Pie wedges are sorted, largest to smallest, reading counterclockwise from 3:00. If you don't specify the color for the pie wedges, the applet chooses colors, and the largest wedge will be green. If you do specify colors, specify them for every wedge. If you don't specify the chart background color with "bg", the default is white.
One use for this chart is diskpie, which shows how disk is used on your computer.
To copy the binaries, just click on Pie.class, PieItem.class and PieView.class.
You are welcome to the source, if you
Modern browsers that support the CANVAS tag let you do your pie charts in Javascript instead.
For fancier pie charts, and many other kinds of chart, you may wish to investigate the powerful, complex, and free programs Ploticus and {!gnuplot gnuplot:}. (My How I Filter Spam article has some graphs produced by gnuplot.)