java pie chart (quick debug help)

rh71

No Lifer
Aug 28, 2001
52,844
1,049
126
piechart.java:
import java.applet.Applet;
import java.applet.AppletContext;
import java.awt.*;
import java.net.MalformedURLException;
import java.net.URL;

public class piechart extends Applet
{

public void init()
{
setBackground(Color.white);
}

public void paint(Graphics g)
{
int i = getSize().height;
int j = getSize().width;
int k = Integer.parseInt(getParameter("noofvals"));
float af[] = new float[k];
int ai[] = new int[k];
int ai1[] = new int[k];
int ai2[] = new int[k];
String as[] = new String[k];
float f = Float.valueOf(getParameter("csize")).floatValue();
String s = getParameter("title");
for(int l = 1; l <= k; l++)
{
af[l - 1] = Float.valueOf(getParameter("val" + String.valueOf(l))).floatValue();
as[l - 1] = getParameter("key" + String.valueOf(l));
ai[l - 1] = Integer.parseInt(getParameter("red" + String.valueOf(l)));
ai1[l - 1] = Integer.parseInt(getParameter("green" + String.valueOf(l)));
ai2[l - 1] = Integer.parseInt(getParameter("blue" + String.valueOf(l)));
}

g.drawRect(0, 0, j - 1, i - 1);
g.setFont(new Font("Arial", 1, 12));
g.drawString(s, 10, 20);
g.setColor(Color.black);
g.fillOval(9, Math.round((float)(i / 2) - f / 2.0F) - 1, (int)f + 4, (int)f + 4);
int i1 = 0;
float f1 = 25F;
for(; i1 < k; i1++)
{
g.setColor(new Color(ai[i1], ai1[i1], ai2[i1]));
g.fillRect((int)f + 40, 30 + i1 * 18, 12, 12);
g.fillArc(10, Math.round((float)(i / 2) - f / 2.0F), Math.round(f), Math.round(f), (int)Math.round((double)f1 * 3.6000000000000001D), (int)Math.round((double)af[i1] * 3.6000000000000001D) * -1);
f1 -= af[i1];
if(f1 < 0.0F)
f1 += 100F;
}

i1 = 0;
g.setColor(new Color(0, 0, 80));
g.drawString("KEY", (int)f + 40, 25);
g.setFont(new Font("Arial", 0, 12));
for(; i1 < k; i1++)
g.drawString(as[i1] + " (" + String.valueOf(af[i1]) + "%)", (int)f + 55, 40 + i1 * 18);

g.drawRect((int)f + 35, 10, (int)((float)j - (f + 35F)) - 10, 20 + k * 18);
g.setColor(new Color(0, 0, 80));
g.setFont(new Font("Arial", 0, 10));
g.drawString("my footer here", 3, i - 3);
}

public piechart()
{
}
}
The parameters I give it in an HTML file produce ]THIS piechart result. The HTML code I give it:
<APPLET CODE="piechart.class" HEIGHT=180 WIDTH=360>
(You can alter the height and width of the pie charts to whatever you want)
<param name="title" value="My Title">
(Choose a title for your pie chart)

<param name="csize" value="101">
(This is the diameter of your pie chart, in pixels. You should choose an odd number.)

<param name="noofvals" value="3">
(This controls the number of wedges.)

<param name="val1" value="0">
<param name="val2" value="14.0">
<param name="val3" value="86.0">
(These are the percentages for each wedge. They should add up to 100.)

<param name="key1" value="Dont Want This Red To Show">
<param name="key2" value="Complete">
<param name="key3" value="Remaining Scheduled">
(These are the names for each wedge that will appear in the 'key' part of the chart.)

<param name="red1" value="255">
<param name="red2" value="0">
<param name="red3" value="80">
<param name="green1" value="0">
<param name="green2" value="255">
<param name="green3" value="80">
<param name="blue1" value="0">
<param name="blue2" value="0">
<param name="blue3" value="255">
(Enter a red, green and blue value between 0 and 255 for each wedge to control the colors used in the pie chart)

</APPLET>


I basically need to get rid of the red altogether. I would enter 2 for: <param name="noofvals" value="3">(This controls the number of wedges.), and it won't work. I basically need the JAVA code edited to use only 2 slices, even if it's hard-coded to use 2, that's fine.

Anyone have ideas? Thanks.