这个是在jsp页面做的超链接的 代码。请教高手 帮忙在ActionBean 中做出这种效果第一个页面 index.jsp 
<%@ page contentType="text/html;charset=GBK"%>
<%@ page import="java.awt.Color,
                org.jfree.chart.ChartFactory,
                org.jfree.chart.JFreeChart,
                org.jfree.chart.plot.PlotOrientation,
                org.jfree.chart.servlet.ServletUtilities,
                org.jfree.data.category.CategoryDataset,
                org.jfree.data.general.*,
                org.jfree.chart.plot.CategoryPlot,
                org.jfree.chart.axis.CategoryAxis,
                org.jfree.chart.axis.ValueAxis,
                org.jfree.chart.renderer.category.BarRenderer3D,
                org.jfree.chart.urls.StandardCategoryURLGenerator,
                org.jfree.chart.*,
                org.jfree.chart.entity.*,
                org.jfree.chart.labels.*"%>
<%
java.io.PrintWriter pw=new java.io.PrintWriter(out);
double[][] data = new double[][] {{672}, {325}, {332}, {440}, {550}, {330}};
String[] rowKeys = {"苹果", "梨子", "葡萄", "桔子", "西瓜", "香蕉"};
String[] columnKeys = {""};
CategoryDataset dataset = DatasetUtilities.createCategoryDataset(
        rowKeys,
        columnKeys,
        data);
JFreeChart chart = ChartFactory.createBarChart3D("水果销量图统计",
                  "水果",
                  "销量",
                  dataset,
                  PlotOrientation.VERTICAL,
                  true,
                  false,
                  false);chart.setBackgroundPaint(Color.WHITE);
CategoryPlot plot = chart.getCategoryPlot();CategoryAxis domainAxis = plot.getDomainAxis();
plot.setDomainAxis(domainAxis);ValueAxis rangeAxis = plot.getRangeAxis();
//设置最高的一个 Item 与图片顶端的距离
rangeAxis.setUpperMargin(0.15);
//设置最低的一个 Item 与图片底端的距离
rangeAxis.setLowerMargin(0.15);plot.setRangeAxis(rangeAxis);BarRenderer3D renderer = new BarRenderer3D();
renderer.setBaseOutlinePaint(Color.BLACK);
//设置 Wall 的颜色
renderer.setWallPaint(Color.gray);
//设置每种水果代表的柱的颜色
renderer.setSeriesPaint(0, new Color(0, 0, 255));
renderer.setSeriesPaint(1, new Color(200, 200, 255));
renderer.setSeriesPaint(2, Color.GREEN);
renderer.setSeriesPaint(3, Color.MAGENTA);
renderer.setSeriesPaint(4, Color.GRAY);
renderer.setSeriesPaint(5, Color.CYAN);//设置平行柱的之间距离
renderer.setItemMargin(0.3);//显示每个柱的数值
renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
renderer.setBaseItemLabelsVisible(true);renderer.setBaseItemLabelsVisible(true);
renderer.setBaseItemURLGenerator(new StandardCategoryURLGenerator(
        "detail.jsp", "fruit", ""));
plot.setRenderer(renderer);//设置柱的透明度
plot.setForegroundAlpha(0.5f);
//设置地区、销量的显示位置
//plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_RIGHT);
ChartRenderingInfo info = new ChartRenderingInfo(new   StandardEntityCollection());String filename = ServletUtilities.saveChartAsPNG(chart, 800, 600, info, session);
String graphURL = request.getContextPath() + "/servlet/DisplayChart?filename=" + filename;ChartUtilities.writeImageMap(pw, filename, info, true);
           pw.flush();
%>
<table width="100%">
    <tr>
        <td align="center">
            <img src="<%= graphURL %>" width=800 height=600 border=0 usemap="#<%= filename %>" alt="">
        </td>
    </tr>
</table>
</body>
</html>
第二个页面
detail.jsp
<%@ page contentType="text/html;charset=GBK"%>
<%@ page import="java.awt.Color,
                org.jfree.chart.ChartFactory,
                org.jfree.chart.JFreeChart,
                org.jfree.chart.plot.PlotOrientation,
                org.jfree.chart.servlet.ServletUtilities,
                org.jfree.data.category.CategoryDataset,
                org.jfree.data.general.*,
                org.jfree.chart.plot.CategoryPlot,
                org.jfree.chart.axis.CategoryAxis,
                org.jfree.chart.axis.ValueAxis,
                org.jfree.chart.renderer.category.BarRenderer3D,
                org.jfree.chart.labels.*"%>
<%
String fruit = new String(request.getParameter("fruit"));
int count = 0;
if ("苹果".equals(fruit)) {
    count = 100;
} else if ("梨子".equals(fruit)) {
    count = 26;
} else if ("葡萄".equals(fruit)) {
    count = -20;
} else if ("桔子".equals(fruit)) {
    count = -40;
} else if ("西瓜".equals(fruit)) {
    count = 80;
}
//String address = new String(request.getParameter("address").getBytes("ISO8859_1"), "utf-8");double[][] data = new double[][] {{672 + count}, {325 + count}, {332 + count}, {440 + count},
                                  {550 + count}, {330 + count}, {435 + count}, {553 + count},
                                  {335 + count}, {443 + count}, {378 + count}, {733 + count}};
String[] rowKeys = {"一月份", "二月份", "三月份", "四月份",
                    "五月份", "六月份", "七月份", "八月份",
                    "九月份", "十月份", "十一月份", "十二月份"};
String[] columnKeys = {""};
CategoryDataset dataset = DatasetUtilities.createCategoryDataset(
        rowKeys,
        columnKeys,
        data);JFreeChart chart = ChartFactory.createBarChart3D("2007年度" + fruit + "销量图",
                  "月份",
                  "销量",
                  dataset,
                  PlotOrientation.VERTICAL,
                  true,
                  false,
                  false);chart.setBackgroundPaint(Color.WHITE);
CategoryPlot plot = chart.getCategoryPlot();CategoryAxis domainAxis = plot.getDomainAxis();
plot.setDomainAxis(domainAxis);ValueAxis rangeAxis = plot.getRangeAxis();
//设置最高的一个 Item 与图片顶端的距离
rangeAxis.setUpperMargin(0.15);
//设置最低的一个 Item 与图片底端的距离
rangeAxis.setLowerMargin(0.15);plot.setRangeAxis(rangeAxis);BarRenderer3D renderer = new BarRenderer3D();
renderer.setBaseOutlinePaint(Color.BLACK);
//设置 Wall 的颜色
renderer.setWallPaint(Color.gray);
//设置每种水果代表的柱的颜色
renderer.setSeriesPaint(0, new Color(0, 0, 255));
renderer.setSeriesPaint(1, new Color(200, 200, 255));
renderer.setSeriesPaint(2, Color.GREEN);
renderer.setSeriesPaint(3, Color.MAGENTA);
renderer.setSeriesPaint(4, Color.GRAY);
renderer.setSeriesPaint(5, Color.CYAN);//设置平行柱的之间距离
renderer.setItemMargin(0.3);//显示每个柱的数值
renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
renderer.setBaseItemLabelsVisible(true);plot.setRenderer(renderer);
//设置柱的透明度
plot.setForegroundAlpha(0.5f);String filename = ServletUtilities.saveChartAsPNG(chart, 800, 550, null, session);
String graphURL = request.getContextPath() + "/servlet/DisplayChart?filename=" + filename;
%><table width="100%">
    <tr>
        <td align="center">
            <a href="index.jsp">返回</a>
            <br>
            <img src="<%= graphURL %>" width=800 height=550 border=0 usemap="#<%= filename %>" alt="">
        </td>
    </tr>
</table>
</body>
</html>
请高手帮忙
这是在jsp 中写的 想在Action 中去实现 

解决方案 »

  1.   

    只提供个思路把:
    把jsp中的java代码,也就是生成jfreechat图片的代码移植到Action中,
    将graphURL 保存 到request中,
    在jsp页面中
    <%String graphURL = request.getAttribute("");%><img src=" <%= graphURL %>" width=800 height=550 border=0 usemap="# <%= filename %>" alt=""> 
      

  2.   

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <!-- saved from url=(0050)http://localhost:8080/cellmonitor/Add.do?op=dprint --><HTML><HEAD>
    <META http-equiv=Content-Type content="text/html; charset=iso-8859-1"><MAP id=jfreechart-14675.png name=jfreechart-14675.png><AREA shape=POLY alt="" 
      coords=671,536,671,324,683,316,755,316,755,528,743,536,743,536 
      href="http://localhost:8080/cellmonitor/detail.jsp?fruit=%CF%E3%BD%B6&amp;="><AREA 
      shape=POLY alt="" 
      coords=556,536,556,182,568,174,640,174,640,528,628,536,628,536 
      href="http://localhost:8080/cellmonitor/detail.jsp?fruit=%CE%F7%B9%CF&amp;="><AREA 
      shape=POLY alt="" 
      coords=440,536,440,253,452,245,524,245,524,528,512,536,512,536 
      href="http://localhost:8080/cellmonitor/detail.jsp?fruit=%BD%DB%D7%D3&amp;="><AREA 
      shape=POLY alt="" 
      coords=325,536,325,322,337,314,409,314,409,528,397,536,397,536 
      href="http://localhost:8080/cellmonitor/detail.jsp?fruit=%C6%CF%CC%D1&amp;="><AREA 
      shape=POLY alt="" 
      coords=209,536,209,327,221,319,293,319,293,528,281,536,281,536 
      href="http://localhost:8080/cellmonitor/detail.jsp?fruit=%C0%E6%D7%D3&amp;="><AREA 
      shape=POLY alt="" coords=94,536,94,104,106,96,178,96,178,528,166,536,166,536 
      href="http://localhost:8080/cellmonitor/detail.jsp?fruit=%C6%BB%B9%FB&amp;="></MAP>
    <META content="MSHTML 6.00.3790.630" name=GENERATOR></HEAD>
    <BODY>
    <TABLE width="100%">
      <TBODY>
      <TR>
        <TD align=middle><IMG height=550 alt="" 
          src="Add_doffr_files/DisplayChart.png" width=800 
          useMap="# jfreechart-14675.png" border=0> 
    </TD></TR></TBODY></TABLE></BODY></HTML>
    这是页面的源码。就是没链接 不动的。帮忙看看 
      

  3.   

    大哥,我那里出来的map的href="detail.jsp%3Ffruit%3D%25E8%258B%25B9%25E6%259E%259C%26amp%3B%3D" 怎么会这样阿?连问号和连接符都给转了真郁闷,一直调不出来
      

  4.   

    我照搬的楼主的源码。粘过去后,什么都完好,就是链接不对。
    为什么我的?和连接符,也给转了,怎么办???求求各位高手,帮帮小弟吧。小弟会以救命之恩报答的!!
    唔唔~~~~~~<map id="jfreechart-44836.png" name="jfreechart-44836.png">
    <area shape="poly" coords="671,539,671,325,683,317,755,317,755,531,743,539,743,539" href="detail.jsp%3Ffruit%3D%25E9%25A6%2599%25E8%2595%2589%26amp%3B%3D" alt=""/>
    <area shape="poly" coords="555,539,555,182,567,174,640,174,640,531,628,539,628,539" href="detail.jsp%3Ffruit%3D%25E8%25A5%25BF%25E7%2593%259C%26amp%3B%3D" alt=""/>
    <area shape="poly" coords="439,539,439,254,451,246,524,246,524,531,512,539,512,539" href="detail.jsp%3Ffruit%3D%25E6%25A1%2594%25E5%25AD%2590%26amp%3B%3D" alt=""/>
    <area shape="poly" coords="324,539,324,324,336,316,408,316,408,531,396,539,396,539" href="detail.jsp%3Ffruit%3D%25E8%2591%25A1%25E8%2590%2584%26amp%3B%3D" alt=""/>
    <area shape="poly" coords="208,539,208,328,220,320,292,320,292,531,280,539,280,539" href="detail.jsp%3Ffruit%3D%25E6%25A2%25A8%25E5%25AD%2590%26amp%3B%3D" alt=""/>
    <area shape="poly" coords="92,539,92,103,104,95,176,95,176,531,164,539,164,539" href="detail.jsp%3Ffruit%3D%25E8%258B%25B9%25E6%259E%259C%26amp%3B%3D" alt=""/>
    </map>
     
    <table width="100%"> 
        <tr> 
            <td align="center"> 
                <img src=" /JchartDemo/servlet/DisplayChart?filename=jfreechart-44836.png" width=800 height=600 border=0 usemap=#jfreechart-44836.png alt=""> 
            </td> 
        </tr> 
    </table> 
      

  5.   

     public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
        {
            request.setCharacterEncoding("UTF-8");
            response.setContentType("text/html;charset=UTF-8");
            CategoryDataset dataset = getBarData();
            JFreeChart chart = ChartFactory.createBarChart3D("", "", "", dataset,
                    PlotOrientation.VERTICAL, true, true, true);
            chart.setBorderVisible(false);
            // PrintWriter pw = new PrintWriter(new FileOutputStream("c:/map.zul"));
            PrintWriter pw = response.getWriter();
            chart.setBackgroundPaint(Color.WHITE);
            CategoryPlot plot = chart.getCategoryPlot();        CategoryAxis domainAxis = plot.getDomainAxis();
            plot.setDomainAxis(domainAxis);        ValueAxis rangeAxis = plot.getRangeAxis();
            // 设置最高的一个 Item 与图片顶端的距离
            rangeAxis.setUpperMargin(0.15);
            // 设置最低的一个 Item 与图片底端的距离
            rangeAxis.setLowerMargin(0.15);        plot.setRangeAxis(rangeAxis);        BarRenderer renderer = new BarRenderer();
            // 设置柱的宽度
            renderer.setBaseOutlinePaint(Color.BLACK);
            // 设置 Wall 的颜色
    //        renderer.setWallPaint(Color.gray);
            // 设置每种水果代表的柱的颜色
            renderer.setSeriesPaint(0, Color.red);
            renderer.setSeriesPaint(1, Color.black);
            renderer.setSeriesPaint(2, Color.GREEN);
            renderer.setSeriesPaint(3, Color.MAGENTA);
            renderer.setSeriesPaint(4, Color.GRAY);
            renderer.setSeriesPaint(5, Color.CYAN);        // 设置平行柱的之间距离
            renderer.setItemMargin(0.3);
            // TODO 设置纵坐标
            NumberAxis axis = (NumberAxis) plot.getRangeAxis();
            axis.setTickUnit(new NumberTickUnit(10D));        // 显示每个柱的数值
            renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
            renderer.setBaseItemLabelsVisible(true);        renderer.setBaseItemLabelsVisible(true);
            // fruit,detail为页面的二个参数 detail.jsp?fruit=""& detail=""
            renderer.setBaseItemURLGenerator(new StandardCategoryURLGenerator("detail.jsp", "fruit", "detail"));
            plot.setRenderer(renderer);        // 设置柱的透明度
            plot.setForegroundAlpha(0.5f);
            // 设置地区、销量的显示位置(左右显示)
            // plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_RIGHT);
            ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());        String filename = ServletUtilities.saveChartAsPNG(chart, 500, 200, info, request.getSession());
            // String graphURL = request.getContextPath() +
            // "/DisplayChart?filename=" + filename;
            String graphURL = "C:/Program Files/Apache Software Foundation/Tomcat 6.0/temp/" + filename;
            System.out.println("fileName" + filename + "----" + graphURL);
            // map要和页面中的usemap要一样
            ChartUtilities.writeImageMap(pw, "map", info, true);
            pw.flush();
            // pw.close();
            request.setAttribute("graphURL", graphURL);
            request.setAttribute("filename", filename);
            request.getRequestDispatcher("/test.jsp").include(request, response);    }
      

  6.   

    <%@ page contentType="text/html;charset=UTF-8"%>
    <html>
    <body>
    <table width="100%">
    <tr>
    <td align="center">
    <%
        String graphURL = (String) request.getAttribute("graphURL");
        String filename = (String) request.getAttribute("filename");
    %>
    <img src="<%=graphURL%>" width=500 height=200 border=0
    usemap="#map" alt="查看详细信息">
    </td>
    </tr>
    </table>
    </body>
    </html>