Java Pie Chart

Here is a bare-bones pie chart applet, useful for decorating a web page with live data from a CGI script.

You need Java to see this output.

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.

Written 06/24/97

Updated 08/09/02 with suggestions from Robert Beck

Updated 04/08/03 to add color choices.

Updated 09/01/04 to add pointer to Ploticus.

Updated 07/18/06 to change "title" to "chartitle".

Updated 01/24/11 to add pointer to Javascript version.

Fancier charting

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.)