Java - Graficos. Longitud de las barras

 
Vista:

Graficos. Longitud de las barras

Publicado por María Ruiz (21 intervenciones) el 18/02/2006 13:12:42
Hola de nuevo.
Mi pregunta es la siguiente:
Tengo este codigo que lo que hace es pintarme un diagrama de barras. El problema es que no consigo que las barras salgan de tamaños diferentes.....
Os pongo el código:
public void paint(Graphics g) {

Principal principal = new Principal();
LinkedList lst = new LinkedList();
lst = principal.ppal();
if(lst.isEmpty()==false){
Graphics2D g2 = (Graphics2D) g;
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
Iterator it;
it=lst.iterator();
int cont=0;
while(it.hasNext())
{
EstructuraPpal aux = (EstructuraPpal) it.next();
cont++;
}

Dimension d = getSize();
int gridWidth = d.width/cont; //6. Me dice el número de barras que vamos a tener
//width ancho. Height alto

int gridHeight = d.height /2;

fontMetrics = pickFont(g2, "Visualización de un disco duro",
gridWidth);

Color fg3D = Color.lightGray;

g2.setPaint(fg3D);
g2.draw3DRect(0, 0, d.width - 1, d.height - 1, true);
g2.draw3DRect(3, 3, d.width -7 , d.height - 7, false);//7
g2.setPaint(fg);

int x = 5;//Esto corresponde con el ancho
int y = 3;//Esto corresponde con el alto
int rectWidth = gridWidth - 2*x;
int stringY = gridHeight - 3 - fontMetrics.getDescent();
int rectHeight = stringY - fontMetrics.getMaxAscent() - y - 2;

// NEW ROW
x = 10;//5
y += gridHeight;
stringY += gridHeight;

it = lst.iterator();
int i=0;
while(it.hasNext())
{
EstructuraPpal aux = (EstructuraPpal) it.next();
if(i==0) g2.setPaint(red);
else if (i==1) g2.setPaint(blue);
else if (i==2) g2.setPaint(yellow);
else if (i==3) g2.setPaint(rosa);
else if (i==4) g2.setPaint(cyan);
else if (i==5) g2.setPaint(fg);
else if (i==6) g2.setPaint(naranja);
else if (i==7) g2.setPaint(gris);
else if (i==8) g2.setPaint(magenta);
else if (i==9)
{
g2.setPaint(green);
i=-1;
}
g2.fill(new Rectangle2D.Double(x, y, rectWidth, rectHeight));
g2.setPaint(fg);
g2.drawString(aux.getNombre(), x, stringY);
x += gridWidth;
i++;
}}

}
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder