help me about image chart
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Qin_Ji
Posted On:   Wednesday, May 30, 2001 12:39 AM

please tell me this program's arithmetic,and what's the mean "rate" import java.applet.Applet; import java.awt.Graphics; import java.awt.Color; import java.awt.Font; public class tu1 extends Applet{ int ybeginv; //the left begin value int ystepv; //the step value of the left y value int ynumber; //the number of the y value int rectwidth; //the width of the little rect. int xbegin; //the bottom line begin xvalue int xend; //the bottom line end xvalue int xstep; //the step of x direction,the amout of pixels int ystep; //the step of y direction int posx1; //the x position of the u   More>>

please tell me this program's arithmetic,and what's the mean "rate"

import java.applet.Applet;
import java.awt.Graphics;
import java.awt.Color;
import java.awt.Font;
public class tu1 extends Applet{
int ybeginv; //the left begin value
int ystepv; //the step value of the left y value

int ynumber; //the number of the y value
int rectwidth; //the width of the little rect.

int xbegin; //the bottom line begin xvalue
int xend; //the bottom line end xvalue

int xstep; //the step of x direction,the amout of pixels
int ystep; //the step of y direction

int posx1; //the x position of the upleft point
int posy1; //the y position of the upleft point
int posy2; //the y position of the downleft point

int diffx; //the move value of x,y
int x1[]; //the value of abstract x position value
float y1[]; //the value of abstract left y position value
//int y2[]; //the value of abstract right y position value

Color linecolor1,rectcolor,linecolor2; //define the color of the line and
int endlength; //the x drection number of value
int newposy; //if the y begin value is not 0,then you must use the new posy instead of posy

String shead,sleft,sbottom; //the display string

private Font font1,font2;

public void init()
{
//set the initial values.
//SetValue(0,10,6,1994,1998,50,50,50,50,20,20);
SetValue(0,10,6,1994,1998,50,50,50,50,20,20);
//set two kinds of font
SetFont();

//set the string to display
SetString("content","trafic","year");

SetColor(Color.yellow,Color.green,Color.blue);
}

public void paint(Graphics g)
{
//draw the left line and the center line.
DDraw(g);

int number=0;
int posy=0;
//draw the short line of the left and right line.
DrawSL(g,number,posy);

//draw the four string
DrawString(g);

//draw the line
DrawLine(g);

y1[0]=(float)(10.6) ;
y1[1]=(float)(16);
y1[2]=(float)17.1;
y1[3]=(float)18.2;
y1[4]=(float)31.3;//through database it will be changed

for (int i=0;i <(xend-xbegin+1);i++)
Draw3DRound(g,y1[i],i);

}

public void Draw3DRound(Graphics g,float y,int i)
{

int xpos,ypos;
int height;
g.setColor(linecolor1);
float rate;//what means "rate"
rate=y/(float)(ystepv)-(ybeginv/ystepv);

height=posy2-(int)(rate*ystep);
xpos=posx1+(i+1)*xstep;

if (height==posy2)
{
g.setColor(rectcolor);
g.drawLine(xpos,height,xpos+rectwidth,height);
g.drawString( Float.toString(y),xpos,height-rectwidth/2);
}
else
{

g.drawOval(xpos,height-rectwidth/4,rectwidth,rectwidth/2);

g.fillRect(xpos,height,rectwidth,(int)(rate*ystep)-rectwidth/2);
g.fillArc(xpos,posy2-rectwidth*3/4,rectwidth,rectwidth/2,0,-180);

g.fillOval(xpos,height-rectwidth/4,rectwidth,rectwidth/2);
g.setColor(rectcolor);
g.drawLine(xpos,height,xpos,posy2-rectwidth/2);
g.drawLine(xpos+rectwidth,height,xpos+rectwidth,posy2-rectwidth/2);
g.drawOval(xpos,height-rectwidth/4,rectwidth,rectwidth/2);
g.drawArc(xpos,posy2-rectwidth*3/4,rectwidth,rectwidth/2,0,-180);

g.setColor(Color.black);
g.drawString( Float.toString(y),xpos,height-rectwidth/2);
}
}

//initialize the member values so that you can change the picture.
public void SetValue(int cybeginv,int cystepv,int cynumber,int cxbegin,int cxend,int cxstep,int cystep,int cposx1,int cposy1,int crectwidth,int cdiffx)
{
ybeginv=cybeginv; //the left begin value
ystepv=cystepv;

ynumber=cynumber;

xbegin=cxbegin;
xend=cxend;

xstep=cxstep;
ystep=cystep;
posx1=cposx1;
posy1=cposy1;
posy2=cposy1+ynumber*ystep;

x1=new int [xend-xbegin+1];
y1=new float [xend-xbegin+1];

rectwidth=crectwidth;
diffx=cdiffx;
}

//initialize the string to display
public void SetString(String head,String left,String bottom)
{
shead=new String(head);
sleft=new String(left);
sbottom=new String(bottom);
}

//set the font using for display the word
public void SetFont()
{
font1=new Font("TimesRoman",Font.BOLD,18);
font2=new Font("TimesRoman",Font.PLAIN,12);
}

//set the default color
public void SetColor(Color c1,Color c2,Color c3)
{
linecolor1=c1;
rectcolor=c2;
linecolor2=c3;
}

//draw the three big line.
public void DDraw(Graphics g)
{
//draw the left line
g.setColor(Color.black);
g.drawLine(posx1,posy1,posx1,posy2);

endlength=posx1+xstep*(xend-xbegin+3); //add more than one step

g.drawLine(posx1,posy2,endlength,posy2);

}

//draw the short line of the left and right edge.
public void DrawSL(Graphics g,int number,int posy)
{
for (int i=0;i <=ynumber;i++)
{
number=ybeginv+i*ystepv;
posy=posy2+5-(i*ystep);

if (posy>posy2)
posy=posy2;

g.setColor(Color.black);
g.drawString(Integer.toString(number),posx1-40,posy);
posy=posy2-(i*ystep);
g.drawLine(posx1,posy,posx1+5,posy);
}

int posx=0;
for (int i=0;i <(xend-xbegin+1);i++)
{
number=xbegin+i;
posx=posx1+(xstep*(i+1));
g.drawString(Integer.toString(number),posx,posy2+20);
x1[i]=number;
}
posx=posx+xstep;
g.drawString(sbottom,posx,posy2+20);
}

//draw the left,center string.
public void DrawString(Graphics g)
{
int x;
int y;
g.setFont(font1);
//display the center words
x=posx1+(xend-xbegin)*xstep/2;
y=posy1-30;
if (y <0)
y=0;
g.drawString(shead,x,y);
//display the left words
g.setFont(font2);
x=posx1-40;
if (x <0)
x=0;
y=posy1-20;
if (y <0)
y=0;
g.drawString(sleft,x,y);
}

//draw the new line
public void DrawLine(Graphics g)
{
g.setColor(linecolor2);
int posx;
int posy;
int posy1;
int xvalues[];
int yvalues[];
xvalues=new int[4];
yvalues=new int[4];
for (int i=0;i <=ynumber;i++)
{
posy=posy2-(i*ystep);
posx=posx1+diffx;
posy1=posy-diffx;
g.drawLine(posx1,posy,posx,posy1);
g.drawLine(posx,posy1,posx1+xstep*(xend-xbegin+3)+diffx,posy1);

}
xvalues[0]=posx1;
yvalues[0]=posy2;
xvalues[1]=posx1+diffx;
yvalues[1]=posy2-diffx;
xvalues[2]=posx1+xstep*(xend-xbegin+3)+diffx;
yvalues[2]=posy2-diffx;
xvalues[3]=posx1+xstep*(xend-xbegin+3);
yvalues[3]=posy2;
//g.setColor(Color.blue);
g.fillPolygon(xvalues,yvalues,4);

}
}

   <<Less
About | Sitemap | Contact