热门文章 | 热门软件| 热门源码 | 热门电影 | 知识库 | 联系我们
软件 源码 教程 影视 健康 招聘
  HTML | JavaScript | ASP | PHP | JSP | NET | VB | VC | VF | Windows | Linux | Mysql | Mssql | Oracle | Struts 
当前位置: 创世纪计算机资源网 -> 文章频道 ->java 
站内搜索:
使用JFreeChart来创建基于web的带交互功能的PIE图表(二)(1)
作者:wiregate 来源:blog 整理日期:2007-8-17

下面是一个通用的饼图生成sevlet
用法是<IMG alt="Pie chart of summary by reason" useMap=#svcGroupCodeMap border=0
            src="pieChart?width=760&height=200&formName=eRAMMISummaryReasonCodeForm&property=re
sult&field1=reasonCode&field2=totalCharge&elemCount=5&numFlag=$&showPercent
=true&mapName=svcGroupCodeMap&linkBase=mmiSummaryByReason.do&linkParaKe
y=svcGroupCode" />
  pieChart在session内存中生成了一个图形的MAP对象,如果要使用则应放在最后面并有一段延时:
<%
try{
out.flush();
java.lang.Thread.sleep(1000);
}
catch (Exception delayEx){

}
%>
            <logic:notEmpty name="svcGroupCodeMap" scope="session">
                <bean:write name="svcGroupCodeMap" scope="session" filter="false"/>
            </logic:notEmpty>


下面的这个这个通用的饼图sevlet的代码,基本思路是利用Session中的一些数据生成饼图,formName一般是struts中的一个form, property是这个form中的一个List对象它保存有一系列饼图需要的数据,field1,field2指的是List元素中的两个属性用来提取饼图需求的数据,其它的参数可有可无,不重要, mapName表示需求生成img的MAP图 .
package com.medi.TO.TOOL;

import java.io.*;
import java.lang.reflect.*;
import java.text.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;

import java.awt.*;

import org.jfree.chart.*;
import org.jfree.chart.labels.*;
import org.jfree.chart.plot.*;
import org.jfree.data.*;
import org.jfree.chart.urls.StandardPieURLGenerator;
/**
 * Title: 
 * Description: send a PIE chart to brower show the data from session of request refer to

 * Copyright: Copyright (c) 2004
 * Company: medi.com
 * @author Xuxi.Chen
 * @version 1.0
 */
public class PieChartServlet extends HttpServlet {
    private static final String CONTENT_TYPE = "image/png";

    //Process the HTTP Get request
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws
        ServletException, IOException {
        execute(request, response);
    }

    //Process the HTTP Post request
    public void doPost(HttpServletRequest request, HttpServletResponse response) throws
        ServletException, IOException {
        execute(request, response);
    }

    public void execute(HttpServletRequest request, HttpServletResponse response) throws
        ServletException, IOException {
        try {
            String title = request.getParameter("title");
            String formName = request.getParameter("formName");
            boolean bLegend = true;
            if (request.getParameter("legend") != null && request.getParameter("legend").equals("false")) {
                bLegend = false;
            }
            boolean bShowLabel = true;
            if (request.getParameter("showLabel") != null && request.getParameter("showLabel").equals("false")) {
                bShowLabel = false;
            }
            int iLegDire = 3;

[1]  [2]  
相关文章