最近一直在搞 jfreechart ,所以总结了一下一个页面实现多个图。
思路:
img中src是一个请求,action中方法返回流。action中只有一个jfreechart实体类
页面:
- <img src="请求"/>
<img src="请求"/>
action 方法:
- /**
- * 输出区域饼状图
- * @return
- * @throws Exception
- */
- public void marketArea() throws Exception {
- HashMap<String, String> conditions = new HashMap<String, String>();
- conditions.put("placeId", this.getSessionplaceid());
- this.idcards = this.supplierService.searchIdcardDataSet(conditions);
- this.chart = JFreeChartUtil.createAreaChart(JFreeChartUtil.createAreaPieDataset(idcards));
- ChartUtilities.writeChartAsPNG(this.getResponse().getOutputStream(), chart, 800, 700); //这一步很重要
- }
/** * 输出区域饼状图 * @return * @throws Exception */ public void marketArea() throws Exception { HashMap<String, String> conditions = new HashMap<String, String>(); conditions.put("placeId", this.getSessionplaceid()); this.idcards = this.supplierService.searchIdcardDataSet(conditions); this.chart = JFreeChartUtil.createAreaChart(JFreeChartUtil.createAreaPieDataset(idcards)); ChartUtilities.writeChartAsPNG(this.getResponse().getOutputStream(), chart, 800, 700); //这一步很重要 }
完毕。
多个图 就多个 img 标签 多个请求。action中多个方法,chart 对象只有一个就可以了。
如果img标签的src是一个请求,那么页面会首先调用这个请求,到类中查找对应的方法,然后得到此方法的返回值,显示。