java 3d 报表_java从excel中读取数据用报表显示,报表怎么做啊,急

展开全部

public class Report {

/**作用:报表样式的枚举,该类的getvalue方法返回对应值。

* Columns_2DVer:2D柱状62616964757a686964616fe4b893e5b19e31333332623939垂直报表。

* Columns_3DVer:3D柱状垂直报表。

* Columns_2DHor:2D柱状水平报表。

* Columns_3DHor:3D柱状水平报表。

* */

public enum ReportType{

Columns_2DVer("Z2DV"),

Columns_3DVer("Z3DV"),

Columns_2DHor("Z2DH"),

Columns_3DHor("Z3DH"),

LineReport_2D("Line2D"),

LineReport_3D("Line3D"),

PieReport_2D("Pie2D"),

PieReport_3D("Pie3D");

private ReportType(String a){

this.str=a;

}

private String str;

public String getvalue(){

return this.str;

}

}

/**作用:作为创建报表时的参数。

* 成员1:报表的标题。

* 成员2:报表的横坐标标题。

* 成员3:报表的纵坐标标题。

* 成员4:JSP页面的request对象。

* 成员5:报表所保存的文件名。

* 成员6:报表的长度。

* 成员7:报表的宽度。

* 成员8:报表的背景颜色,默认为白色。

* 成员9:报表网格中竖线的颜色,默认为黑色。

* 成员10:报表网格中横线的颜色,默认为黑色。

* 成员11:报表横轴内容的数组。

* 成员12:报表纵轴内容的list数组。

* 成员13:提示信息。如果写入多个提示信息,报表就变成多柱状。

* 成员14:报表的模式。详见reportType枚举类

* 成员15:饼状图专用的数值数组。数组的和必须等于1.

* 注意1:要在JSP页面引入该类型才能使用,横纵轴数组的长度必须一致。

* 注意2:如果在提示信息数组中写入了多个提示信息,那么报表纵轴内容的

* list中就必须存放入和它数量一致的int数组。否则会出错。

* */

public class ReportClass{

public String ReportTitle;

public String xTitle;

public String yTitle;

public HttpServletRequest request;

public String filename;

public int width;

public int height;

public Color BackgroundColor=Color.WHITE;

public Color ylineColor=Color.BLACK;

public Color xlineColor=Color.BLACK;

public String[] xValues;

public ArrayList yValue=new ArrayList();

public String[] helpstr;

public String reportType;

public double[] PieValue;

}

/**作用:创建一个指定类型和数据的图表。

* 参数1:ReportClass类型,各成员具体作用参见ReportClass说明

* 返回值:String类型,在JSP页面可以直接out.println显示图形。

* 注意1:ReportClass类型中,必须设置的成员主要有:

* 1、ReportTitle 2、request 3、filename 4、width 5、height 6、reportType

* 注意2:如果要生成饼状图,还需要设置:

* 1、xValues 2、PieValue 这两个数组的长度必须一致

* 注意3:如果要生成柱状图或折线图,还需要设置:

* 1、xValues 2、yValue 3、helpstr

* yvalue数组总和必须等于1.即100%.

* 如果要生成多柱状或折线图,则需要设置helpstr长度。

* yvalue列表的长度必须和helpstr数组长度一致。

* yvalue中的成员数组的长度必须和xvalue数组长度一致。

* */

public String CreateReport(ReportClass rc){

String s="sf";

String str="";

JFreeChart jc=null;

Font titlefont=new Font("宋体",Font.BOLD,20);

Font tickfont=new Font("宋体",0,15);

Font labelfont=new Font("宋体",Font.BOLD,15);

DefaultCategoryDataset ds=null;

DefaultPieDataset pds=null;

if (rc.ReportTitle!=null){

if (rc.reportType.indexOf("Pie")!=-1){//饼状图

pds=new DefaultPieDataset();

double[] ob=rc.PieValue;

for (int i=0;i

pds.setValue(rc.xValues[i], ob[i]);

}

if (rc.ReportTitle!=null){

if (rc.reportType.equals("Pie2D")){

jc=ChartFactory.createPieChart(rc.ReportTitle,pds,true, true, false);

}

else if (rc.reportType.equals("Pie3D")){

jc=ChartFactory.createPieChart3D(rc.ReportTitle,pds,true, true, false);

}

jc.getTitle().setFont(titlefont);

jc.getLegend().setItemFont(labelfont);

jc.setBackgroundPaint(rc.BackgroundColor);//总背景色

jc.setBorderPaint(rc.BackgroundColor);

PiePlot plot=(PiePlot)jc.getPlot();

plot.setBackgroundPaint(rc.BackgroundColor);

plot.setLabelFont(new Font("宋体",0,15));

}

}

else { //柱状或折线图

ds=new DefaultCategoryDataset();

for (int i=0;i

int[] ob=rc.yValue.get(i);

for (int j=0;j

ds.addValue(ob[j], rc.helpstr[i], rc.xValues[j]);

}

}

if (rc.reportType.indexOf("Z2D")!=-1){

PlotOrientation po=null;

if (rc.reportType.indexOf("V")!=-1){

po=PlotOrientation.VERTICAL;

}

else if (rc.reportType.indexOf("H")!=-1){

po=PlotOrientation.HORIZONTAL;

}

jc=ChartFactory.createBarChart(rc.ReportTitle, rc.xTitle, rc.yTitle,

ds, po, true, true, false);

}

else if (rc.reportType.indexOf("Z3D")!=-1){

PlotOrientation po=null;

if (rc.reportType.indexOf("V")!=-1){

po=PlotOrientation.VERTICAL;

}

else if (rc.reportType.indexOf("H")!=-1){

po=PlotOrientation.HORIZONTAL;

}

jc=ChartFactory.createBarChart3D(rc.ReportTitle, rc.xTitle, rc.yTitle,

ds, po, true, true, false);

}

else if (rc.reportType.equals("Line2D")){

PlotOrientation po=PlotOrientation.VERTICAL;

jc=ChartFactory.createLineChart(rc.ReportTitle, rc.xTitle, rc.yTitle,

ds, po, true, true, false);

}

else if (rc.reportType.equals("Line3D")){

PlotOrientation po=PlotOrientation.VERTICAL;

jc=ChartFactory.createLineChart3D(rc.ReportTitle, rc.xTitle, rc.yTitle,

ds, po, true, true, false);

}

jc.getTitle().setFont(titlefont);

jc.getLegend().setItemFont(labelfont);

jc.setBackgroundPaint(rc.BackgroundColor);//总背景色

CategoryPlot cp=jc.getCategoryPlot();

cp.setBackgroundPaint(rc.BackgroundColor);//图形框架背景色

cp.setDomainGridlinePaint(rc.ylineColor);//图形背景网格中竖线的颜色

cp.setDomainGridlinesVisible(true);

cp.setRangeGridlinePaint(rc.xlineColor);//图形背景网格中横线的颜色

cp.getDomainAxis().setTickLabelFont(tickfont);

cp.getDomainAxis().setLabelFont(labelfont);

cp.getRangeAxis().setTickLabelFont(tickfont);

cp.getRangeAxis().setLabelFont(labelfont);

}

try {

File ff=new File(rc.request.getRealPath("/")+"file");

if (!ff.exists()){

ff.mkdir();

}

File file=new File(rc.request.getRealPath("/")+"file/"+rc.filename);

if (!file.exists()){

file.createNewFile();

}

ChartUtilities.saveChartAsJPEG(file, jc, rc.width, rc.height);

str="%22+file.getPath()+%22";

return str;

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

return null;

}

}

else {

return null;

}

}} 以前写的一个报表的集成,可以生成任何形式的报表,要引入JFreeChar.你可以慢慢研究下...

本回答由网友推荐

2Q==

已赞过

已踩过<

你对这个回答的评价是?

评论

收起

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值