日期:2014-05-20  浏览次数:20832 次

jfreechart热点
s2sh框架
热点生成方法:
Java code

public static String getFileName(HttpSession session,int h,int w,JFreeChart chart) throws IOException{
        //
        HttpServletResponse response = ServletActionContext.getResponse();
        StandardEntityCollection sec = new StandardEntityCollection(); 
        ChartRenderingInfo info = new ChartRenderingInfo(sec);
        response.setContentType("text/html");
        PrintWriter write1 = response.getWriter();
        String filename=ServletUtilities.saveChartAsPNG(chart, w, h,info, session);
        ChartUtilities.writeImageMap(write1, filename, info, true);
        write1.flush();
        System.out.println("标记下");
        System.out.println(info);
        return filename;
    }


action方法:
Java code

public String createDataset() throws IOException{
        System.out.println("进入createDataset方法");
        int cid=Integer.parseInt(request.getParameter("cid"));
        System.out.println(cid);
        List<Pouringgirder1> list=this.prg1Biz.findPouringgirder1ByHql(cid);
        System.out.println(list.size());
        
        DefaultPieDataset dataset=new DefaultPieDataset();
        for(int i=0;i<list.size();i++){
            dataset.setValue(list.get(i).getPgrId().toString(),list.get(i).getEvaluation());
        }
        JFreeChart chart=JChartUtil.createPieChart2D("评价", dataset);        
        String filename=JChartUtil.getFileName(request.getSession(), 200, 300, chart);        
        String graphURL = request.getContextPath()+ "/servletDisplayChart?filename=" + filename;
        request.setAttribute("filename", filename);
        request.setAttribute("graphURL", graphURL);
        return "succ";
    }


jsp代码:
Java code

<img src="${request.graphURL }" border=0 usemap="#${request.filename }"/>


页面的class代码:
Java code

<map id="jfreechart-22399.png" name="jfreechart-22399.png">
<area shape="poly" coords="173,152,156,157,139,156,123,151,109,141,98,127,92,111,91,94,95,77,104,62,117,50,132,43,150,40,150,98,150,98" onMouseOver="return overlib('3: (85, 57%)');" onMouseOut="return nd();" nohref="nohref"/>
<area shape="poly" coords="150,40,160,41,169,43,178,47,186,53,193,60,199,68,204,77,207,86,208,96,207,106,205,116,202,125,196,133,190,141,182,147,173,152,150,98,150,98" onMouseOver="return overlib('2: (65, 43%)');" onMouseOut="return nd();" nohref="nohref"/>
</map>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>center4</title>
<link rel="stylesheet" href="../../css/c.css" type="text/css"></link>
</head>

<body onload="doshow(0)" >
 <div class="all">
     <div class="right">
        <div class="chart">
        chart<br/>
        <img src="/suomeng1/servletDisplayChart?filename=jfreechart-22399.png" border=0 usemap="#jfreechart-22399.png"/>
        </div>
    </div>
 </div>
</body>
</html>



在class代码中,map信息跑到了页面头部,热点信息不显示,鼠标停留无反应!
求解决办法!

------解决方案--------------------
没整过jfreechat 一直用chartDirector
------解决方案--------------------
这样看不出啥效果啊,建议去找个已经实现功能了的例子先参考一下。