Código PHP:
private class Grafica implements ActionListener {
public void actionPerformed(ActionEvent e) {
JInternalFrame w;
w = new JInternalFrame();
w.setClosable(true);
w.setMaximizable(true);
w.setIconifiable(true);
w.setTitle("Gráfica");
w.setResizable(true);
w.setContentPane(new DrawPanel());
w.setBounds(360, 10, 270, 250);
lc.add(w);
try { w.setSelected(true); } catch (java.beans.PropertyVetoException e2) {}
}
}
private class DrawPanel extends JLabel {
float md=0,miny=Float.parseFloat(dtm.getValueAt(0,5).toString()),mh=0,ma=0;
int n = dtm.getRowCount();
float D[]=new float[n],H[]=new float[n],Hh[]=new float[n];
public DrawPanel() {
super.setBackground(Color.white);
super.setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR));
try {
for(int i=0;i<dtm.getRowCount();i++) {
D[i] = ((Float)dtm.getValueAt(i,2)).floatValue();
H[i] = ((Float)dtm.getValueAt(i,4)).floatValue();
Hh[i] = ((Float)dtm.getValueAt(i,5)).floatValue();
if(D[i]>md) md = D[i];
if(Hh[i]>mh) mh = Hh[i];
if(Hh[i]<miny) miny = Hh[i];
if(H[i]>ma) ma = H[i];
}
}
catch(NullPointerException ex) {JOptionPane.showMessageDialog(this, ""+ex+miny);}
}
String round(double num,int prec) {
int temp = (int)num;
double dec = Math.abs(num-temp);
dec *= Math.pow(10,prec);
String deci = Double.toString(Math.round(dec)/Math.pow(10,prec));
deci = deci.substring(2);
return ((num<0&&temp==0)?"-"+Integer.toString(temp):Integer.toString(temp))+"."+deci;
}
public void paintComponent(Graphics g) {
int mx,my,offset=20;
mx = getSize().width-60;
my = getSize().height-2*offset;
float x1,x2,y1,y2,my2=(float)(1.9*miny);
g.setColor(new Color(192,192,192));
for(int i=0;i<=n;i++) {
y1 = my-my*i/n+offset;
g.drawLine(30,(int)y1,mx+50,(int)y1);
x1 = mx*i/n+30;
g.drawLine((int)x1,(int)my+offset,(int)x1,(int)offset/2);
x2 = i*md/n; //escala bien
y2 = i*(mh-my2/2)/n+my2/2; //escala bien
g.drawString(Integer.toString((int)Math.round(y2)),2,(int)y1+3);
g.drawString(round(x2,3),(int)x1-5,(int)my+offset+15);
}
//ejes
g.setColor(new Color(18,18,175));
g.drawLine(30,(int)my+offset,mx+50,(int)my+offset);
g.drawLine(30,offset/2,30,(int)my+offset);
//fin ejes
for (int i=0;i<n-1;i++) {
x1 = D[i]*mx/md+30;
x2 = D[i+1]*mx/md+30;
y1 = my-my*(Hh[i]-my2/2)/(mh-my2/2)+offset;
y2 = my-my*(Hh[i+1]-my2/2)/(mh-my2/2)+offset;
g.setColor(Color.blue);
g.drawLine((int)x1,(int)y1,(int)x2,(int)y2);
y1 = H[i];
y2 = H[i+1];
g.setColor(Color.red);
g.drawLine((int)x1,(int)(my-y1*my/20/ma)+20,(int)(x2),(int)(my-y2*my/20/ma)+20);
}
}
}
Gracias por su ayuda