开发者博客:http://www.developsearch.com
/**
* 拼装报表 饼图 image jfreeChart
*
* @param json
* @param res
* @throws IOException
* @throws Exception
*/
public String fetchContentTypeStatChartData(GetContentTypeStateResponse res) throws IOException
{
Double[] data = new Double[8];
String[] keys = {"电子书刊", "媒体教材","案例","量规集","教学工具和模板","文献资料","索引目录","课程"};
String imageNum = null;
if( null != res.getContentTypes() && res.getContentTypes().size() > 0 )
{
ContentTypeState content = res.getContentTypes().get(0);
data[0] = Double.parseDouble(content.getBooks().substring(0,content.getBooks().length()-1));
data[1] = Double.parseDouble(content.getMedia().substring(0,content.getMedia().length()-1));
data[2] = Double.parseDouble(content.getCaze().substring(0,content.getCaze().length()-1));
data[3] = Double.parseDouble(content.getGauge().substring(0,content.getGauge().length()-1));
data[4] = Double.parseDouble(content.getTemplate().substring(0,content.getTemplate().length()-1));
data[5] = Double.parseDouble(content.getDocument().substring(0,content.getDocument().length()-1));
data[6] = Double.parseDouble(content.getIndexCata().substring(0,content.getIndexCata().length()-1));
data[7] = Double.parseDouble(content.getCourse().substring(0,content.getCourse().length()-1));
ChartUtil chartUtil = ChartUtil.getInstance();
imageNum = chartUtil.drawPieChart3D(chartUtil.getDataPieSetByUtil(data, keys), "资源类型统计报表", "", 600, 400, "contentTypeStat");
}
return imageNum;
}
/**
* 拼装报表 柱状图 image jfreechart
*
* @param json
* @param res
* @throws UnsupportedEncodingException
* @throws Exception
*/
public String fetchSingleExerciseDetailChartData(GetSingleExerciseDetailResponse res) throws UnsupportedEncodingException
{
String imageNum = "";
if( null != res.getDetails() && res.getDetails().size() > 0 )
{
double[][] _data = new double[res.getDetails().size()][5];
String[] rowKeys = new String[res.getDetails().size()];
String[] columnKeys = { "A", "B", "C", "D", "E" };
/* 测试数据
double[][] _data = new double[][]{
{ 0.21, 0.66, 0.23, 0.40, 0.26 },
{ 0.21, 0.66, 0.23, 0.40, 0.26 },
{ 0.25, 0.21, 0.10, 0.40, 0.16 }
};
String[] rowKeys = { "aa", "bb", "cc" };*/
for( int i=0; i<res.getDetails().size(); i++)
{
SingleExerciseDetail single = res.getDetails().get(i);
rowKeys[ i ] = single.getClassName();
_data[ i ][ 0 ] = Double.valueOf(single.getPercentA());
_data[ i ][ 1 ] = Double.valueOf(single.getPercentB());
_data[ i ][ 2 ] = Double.valueOf(single.getPercentC());
_data[ i ][ 3 ] = Double.valueOf(single.getPercentD());
_data[ i ][ 4 ] = Double.valueOf(single.getPercentE());
}
CategoryDataset c_dataset = DatasetUtilities.createCategoryDataset(rowKeys, columnKeys, _data);
imageNum = ChartUtil.getInstance().drawBarChart3D( c_dataset, "单次作业练习成绩统计报表", "", 600, 400,"singleExerciseDetail");
}
return imageNum;
}
<div id="chartdiv" align="center"></div>
//页面图形展示 饼图
createReportImage("contentTypeStat", data.imageNum);
//页面图形展示 柱状图
createReportImage("singleExerciseDetail", data.imageNum);
/**
* 生成报表图形文件
* @param folder 文件夹路径
* @param imageName 文件名
*/
function createReportImage(folder,imageName){
if(isEmpty(imageName)){
var chartdiv = document.getElementById("chartdiv");
chartdiv.innerHTML="";
var img = document.createElement("img");
var imgSrc = CONTEXT_PATH + "/images/chart/"+folder+"/"+imageName+".png";
img.setAttribute("src",imgSrc);
chartdiv.appendChild(img);
}
}