在网上很难找到做报表用的各种用图。下面是我最近的新作。一点点小东西,
与大家分享,如果有什么问题请发信到[email protected]
applet 原码,用jcreator打开即可。
import java.awt.*;
import java.awt.geom.*;
public class distribut extends javax.swing.JApplet
{
private int data[], i;
// the init function ;
public void init()
{
data=new int[12];
data[0]=400;
data[1]=50;
data[2]=200;
data[3]=50;
data[4]=600;
data[5]=50;
data[6]=400;
data[7]=10;
data[8]=400;
data[9]=50;
data[10]=400;
data[11]=50;
}
file://tho body of paint;
public void paint(Graphics g )
{
Graphics2D screen2D=(Graphics2D)g;
GradientPaint gp=new GradientPaint(0F,0F,Color.BLACK,50F,50F,Color.BLACK,false);
screen2D.setPaint(gp);
GeneralPath f1=new GeneralPath();
f1.moveTo(10,223);
for(i=0;i<12;i++)
{
g.setColor(Color.orange);
f1.lineTo((float)50+i*40F,(float)225-data[i]/4F);
if(i==11)
{
f1.lineTo((float)490F,(float)223F);
}
}
f1.closePath();
screen2D.fill(f1);
/*
g.setColor(Color.orange);
f1.lineTo(50F,(float)225-data[0]/4F );
f1.lineTo(90F,(float)225-data[1]/4F );
f1.lineTo(130F,(float)225-data[2]/4F);
f1.lineTo(170F,(float)225-data[3]/4F);
f1.lineTo(210F,(float)225-data[4]/4F);
f1.lineTo(250F,(float)225-data[5]/4F);
f1.lineTo(290F,(float)225-data[6]/4F);
f1.lineTo(330F,(float)225-data[7]/4F);
f1.lineTo(370F,(float)225-data[8]/4F);
f1.lineTo(410F,(float)225-data[9]/4F);
f1.lineTo(450F,(float)225-data[10]/4F);
f1.lineTo(490F,(float)225-data[11]/4F);
f1.lineTo(490F,223F);
f1.closePath();
screen2D.fill(f1);
*/
for(i=0;i<12;i++)
{
Font f33=new Font("Verdana",Font.BOLD,9);
g.setFont(f33);
g.setColor(Color.RED);
g.drawString(data[i]+"",50+i*40-7,220-data[i]/4-2);
}
g.setColor(Color.BLACK);
Font f11=new Font("Verdana",Font.BOLD,25);
g.setFont(f11);
g.drawString("the product of last year",150,25);
Font f22=new Font("Verdana",Font.BOLD,11);
g.setFont(f22);
for(i=0;i<=7;i++)
{
g.drawString(700-i*100+"",0,52+i*25);
}
g.drawLine(10,30,10,224);
g.drawLine(10,224,550,224);
for(i=0;i<12;i++)
{
g.drawLine(50+i*40,30,50+i*40,224);
}
for(i=0;i<12;i++)
{
g.setColor(Color.BLACK);
g.drawString(i+1+"M",50+i*40,240);
}
}
}
html原码如下:
<html>
<head>
<title>bars</title>
</head>
<body>
<applet code=distribut.class width=800 height=500 >
</applet>
</body>
</html>
结果如下:
本文地址:http://com.8s8s.com/it/it16928.htm