使用api绘制统计图

来源:互联网 发布:node 编辑:程序博客网 时间:2024/04/30 07:19


润乾报表提供了api接口,供用户进行设计开发,给客户自行开发程序很大的扩展空间,并且也使得开发变得更加灵活,控制性更强。本篇文章主要介绍一下如何通过api接口绘制一个统计图。

例如客户想画一个柱状图,下面讲一下实现过程。新建一个jsp。

jsp需要引入的相关包,因为本例比较简单所以引用的包也较少。

<%@ page import=”com.runqian.report4.usermodel.*”%>
<%@ page import=”com.runqian.report4.model.*”%>
<%@ page import=”com.runqian.report4.util.*”%>
<%@ page import=”com.runqian.report4.usermodel.graph.*”%>

第一步新建一个默认的空报表,代码如下

ReportDefine rd = new ReportDefine2(1, 1);//一行一列的报表
IRowCell rowCell = rd.getRowCell(1);
IColCell colCell = rd.getColCell((short)1);
rowCell.setRowHeight((float)150);
colCell.setColWidth((float)150);

第二步构造一个空的统计图:

// 构造一个空统计图
GraphProperty gp = new GraphProperty();

// 设置统计图类型–柱状图
gp.setType(GraphTypes.GT_COL);

// 设置坐标轴颜色
gp.setAxisColor(238130238);

// 设置柱形图间距
gp.setBarDistance(”20″);

// 设置统计图标题
gp.setGraphTitle(”统计图例子”);

// 设置标题与图形之间的距离
gp.setTitleMargin(”10″);

// 设置横轴标题
gp.setXTitle(”横坐标轴”);

// 设置纵轴标题
gp.setYTitle(”纵坐标轴”);

第三步,构造分类轴和系列值的定义,并把他们赋给统计图,

GraphCategory[] graphCat = new GraphCategory[1];
GraphSery[] sery=new GraphSery[1];
for(int i = 0; i <graphcat.length;i ++){="" 由于本例比较简单,所以这个循环看起来是多余的,但是在实际的应用中,这个循环="" 在赋值过程中很有用处
GraphCategory category = new GraphCategory();
category.setCategory(”销量”);
graphCat[i] = category;

//根据分类设置它对应的系列对象

for(int j = 0; j <sery.length; ){
GraphSery gSery = new GraphSery();
gSery.setName(”name”);
gSery.setExp(”=200″);
sery[j]=gSery; }
graphCat[i].setSeries(sery);
}
gp.setCategories(graphCat);

最后设置单元格,并设置该单元格的图表

INormalCell iGraphCell = rd.getCell(1,(short) 1);
iGraphCell.setCellType(iGraphCell.TYPE_GRAPH);

iGraphCell.setGraphProperty(gp);

rd.setCell(3, (short)1, iGraphCell);
IByteMap exp3 = new ByteMap();
exp3.put(INormalCell.VALUE, “graph()”);
iGraphCell.setExpMap(exp3);

这样统计图就画完了,在后面加上标签进行解析

//设置request中报表定义对象
String rptName = “RPT_”+Double.toString(Math.random());
request.setAttribute(rptName,rd);

srcType=”defineBean”
beanName=”<%=rptName%>”
/>

这样就可以浏览这个jsp,在页面上可以看到一个有关于销量的统计。

这样就完成了api的统计图设计。有需要的朋友可以用这个作为参考。

0 0
原创粉丝点击