客戶需求:
之前遇到過客戶希望後臺直接獲取到快逸生成統計圖,當時給客戶解決的方法是通過先在快逸報表中設置統計圖,後臺運算後,獲取到報表單元格的值,轉化成ImageValue對象。
實現準備:
1:瞭解清楚客戶需求報表的統計圖類型,並查詢api獲取到對應的byte值
2:獲取分類軸的值,轉化成數組
3:獲取系列名稱,轉化成數組
4:獲取系列值,轉化成數組
5:獲取標題,轉化成數組
代碼:
package com.api;
import java.io.FileOutputStream;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.List;
import com.raq.dm.Sequence;
import com.runqian.report4.model.expression.graph.ExtGraphCategory;
import com.runqian.report4.model.expression.graph.ExtGraphProperty;
import com.runqian.report4.model.expression.graph.ExtGraphSery;
import com.runqian.report4.model.expression.graph.StatisticGraph;
import com.runqian.report4.usermodel.Palette;
import com.runqian.report4.usermodel.graph.GraphProperty;
import com.runqian.report4.usermodel.graph.ImageValue;
public class V4Graph {
//通過參數決定返回那個統計圖,1<=參數<=20
byte[]img=null;
public byte[] getGraps(int num) {
try{
byte[]types={1,14,12,2,7,13,20,22,21,10,15,8,9,5,6,4,17,16,11,29};
String[]cats=new String[]{“Apr”,”Feb”,”Jan”,”Jun”,”Mar”,”May”};
String[]sers=new String[]{“煤“,”石油“,”沼氣“};
int[]vals=new int[]{23,20,10,21,10,5,21,12,3,26,6,5,23,19,4,20,15,8};
String[] tips = new String[]{“a”,”b”,”c”,”a”,”b”,”c”,”a”,”b”,”c”,”a”,”b”,”c”,”a”,”b”,”c”,”a”,”b”,”c”};
GraphProperty graphProp=new GraphProperty();
graphProp.setImageFormat(GraphProperty.IMAGE_PNG);
graphProp.setType(types[num-1]);
ExtGraphProperty extProp = new ExtGraphProperty(graphProp);
ArrayList categories = new ArrayList();
ExtGraphCategory graphCat = null;
for(int c=0;c<cats.length;c++){
graphCat=new ExtGraphCategory();
graphCat.setName(cats[c]);
ArrayList series = new ArrayList();
for(int s=0;s<sers.length;s++){
ExtGraphSery graphSery = new ExtGraphSery();
graphSery.setName(sers[s]);
graphSery.setValue(vals[(c*3+s)]);
graphSery.setTips(tips[c*3+s]);
series.add(graphSery);
graphCat.setSeries(series);
}
categories.add(graphCat);
}
extProp.setCategories(categories);
// 設置調色板
extProp.setPalette(Palette.getDefaultPalette());
// 計算統計圖
StatisticGraph sg = new StatisticGraph(extProp, 360, 220); // 三個參數分別爲:統計圖屬性,寬度,高度
ImageValue value = sg.calc();
img = value.getValue();
}
catch (Throwable e) {
e.printStackTrace();
}
return img;
}
}
總結:
例子中循環遍歷,生成了20個統計圖,可根據客戶具體需求更改代碼。