定制你自己的图形报表 (1)

王朝java/jsp·作者佚名  2006-01-08
窄屏简体版  字體: |||超大  

下面两个程序告诉你如何定制你自己的图形报表,在eclipse+myeclipse和tomcat5.0+IE5.0下调试通过.支持中文显示.

建议先看参数档在定制你自己的图形报表(4),有问题 联系:dengzi725@sohu.com

draw.java 是个applet,具体如下:(程序中有注释)

import java.applet.Applet;

import java.awt.*;

import java.awt.geom.*;

import java.util.*;

/*

* Created on 2003-12-9

*

* To change the template for this generated file go to

* Window>Preferences>Java>Code Generation>Code and Comments

*/

/**

* @author dengmc

*

* To change the template for this generated type comment go to

* Window>Preferences>Java>Code Generation>Code and Comments

*/

public class draw extends Applet {

/**

* Constructor of the applet.

*

* @exception HeadlessException if GraphicsEnvironment.isHeadless()

* returns true.

*/

private int[] dataAt;

private int[] datapre;

private int[] dataInc;

private double[] moredatay;

private double dataAll;

private int i,x,y,x_span,y_span,x_dist,y_dist,y_upright,x_level,stagger_dist,width,height,n,k1,k2;

private int proportion,y_axis_Not,word_Direction;

private String[] moredatax;

private String y_axis_Proportion,axis_Color,font_Style,bg_Color,t_Title,font_Mode,gridding_Color,t_Unit;

private int view_Proportion,view_Position,chart_Style,color_Mode,cutline_Mode,gridding_Style,table_Fontsize,heading_Fontsize;

/*

* 定义一组用于显示颜色值;

*/

static Color color[]={

new Color(131,66,0),

new Color(163,99,0),

new Color(199,139,60),

new Color(204,141,0),

new Color(255,180,13),

new Color(255,209,107),

new Color(181,131,0),

new Color(210,167,15),

new Color(239,163,74),

new Color(253,195,119),

new Color(255,227,132),

new Color(255,237,180)

};

Collection c1=new Vector();

Collection c2=new Vector();

public void init()

{

n=0;

/*

* 使用vector获取页面提交的数组值;

*/

try

{

for(i=1;;i++)

{

String param_int=this.getParameter("datay"+i);

if(param_int==null) break;

c2.add(param_int);

}

for(i=1;;i++)

{

String param_string=this.getParameter("datax"+i);

if(param_string==null) break;

c1.add(param_string);

}

k1=c1.size();

k2=c2.size();

if(k1==k2)

{

n=k2;

}

dataAt=new int[n];

datapre=new int[n];

dataInc=new int[n];

String []moredataY;

moredatay=new double[n];

moredatax=new String[n];

moredataY=new String[n];

c1.toArray((Object[])moredatax);

c2.toArray((Object[])moredataY);

for(i=0;i<n;i++)

{

moredatay[i]=Double.parseDouble(moredataY[i]);

}

/*

* 获得一个总的值;

*/

int j=0;

while(j<n)

{

dataAll+=moredatay[j++];

}

/*

* 设置增加角度值;

*/

for(i=0;i<n;i++)

{

dataInc[i]=(int)(360*moredatay[i]/dataAll);

if (dataInc[i]<2)

{

dataInc[i]=2;

}

}

/*

* 设置前n项的和;

*/

for(i=1;i<n;i++)

{

dataAt[0]=0;

dataAt[i]=dataAt[i-1]+dataInc[i-1];

}

/*

* 精度计算;

*/

double[] x;

x=new double[n];

for(i=0;i<n;i++)

{

x[i]=moredatay[i]*100/dataAll;

datapre[i]=(int)(moredatay[i]*100/dataAll);

if(x[i]<0.5)

{

x[i]=0.5;

}

if((x[i]-datapre[i])>=0.5)

{

datapre[i]=datapre[i]+1;

}

}

}

catch(NumberFormatException e)

{

}

try{

//获得图表的标题;

t_Title=this.getParameter("Title");

//获得文字字体;

font_Style=this.getParameter("Font_Style");

//获得表体字体大小;

table_Fontsize=Integer.parseInt(this.getParameter("Table_Fontsize"));

//获得标题字体大小;

heading_Fontsize=Integer.parseInt(this.getParameter("Heading_Fontsize"));

//获得字体样式;

font_Mode=this.getParameter("Font_Mode");

}catch(Exception e)

{

}

try{

//获得显示比例;

view_Proportion=Integer.parseInt(this.getParameter("View_Proportion"));

//获得是否显示纵坐标;

y_axis_Not=Integer.parseInt(this.getParameter("Y_axis_Not"));

//获得纵坐标显示比例;

y_axis_Proportion=this.getParameter("Y_axis_Proportion");

//获得是否显示网格线;

gridding_Style=Integer.parseInt(this.getParameter("Gridding"));

//获得图表显示方式;

chart_Style=Integer.parseInt(this.getParameter("Chart_Style"));

//获得图例显示位置;

view_Position=Integer.parseInt(this.getParameter("View_Position"));

//获得图例显示方式;

cutline_Mode=Integer.parseInt(this.getParameter("Cutline_Mode"));

//获得颜色显示方式;

color_Mode=Integer.parseInt(this.getParameter("Color_Mode"));

//获得坐标轴的文字方向;

word_Direction=Integer.parseInt(this.getParameter("Word_Direction"));

//获得坐标轴的颜色;

axis_Color=this.getParameter("Axis_Color");

//获得网格线的颜色;

gridding_Color=this.getParameter("Gridding_Color");

//获得单位;

t_Unit=this.getParameter("Unit");

}catch(Exception e)

{

}

try{

//获得背景色;

bg_Color=this.getParameter("Bg_Color");

/*

* 确定背景色。

*/

if(bg_Color.equals("blue"))

{

setBackground(Color.blue);

}

if(bg_Color.equals("cyan"))

{

setBackground(Color.cyan);

}

if(bg_Color.equals("gray"))

{

setBackground(Color.gray);

}

if(bg_Color.equals("green"))

{

setBackground(Color.green);

}

if(bg_Color.equals("lightGray"))

{

setBackground(Color.lightGray);

}

if(bg_Color.equals("magenta"))

{

setBackground(Color.magenta);

}

if(bg_Color.equals("orange"))

{

setBackground(Color.orange);

}

if(bg_Color.equals("pink"))

{

setBackground(Color.pink);

}

if(bg_Color.equals("red"))

{

setBackground(Color.red);

}

if(bg_Color.equals("white"))

{

setBackground(Color.white);

}

if(bg_Color.equals("yellow"))

{

setBackground(Color.yellow);

}

}

catch(Exception e)

{

}

}

//end of init();

/*

private String toCh(String source)

{

if ((source == null) || source.equals(""))

return null;

try {

return new String(source.getBytes("GB2312"));

} catch (java.io.UnsupportedEncodingException e) {

return source;

}

}

*/

}

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有  導航