1

我正在使用 JFreeChart,我想使用 servlet/JSP 实现工具提示

代码:小服务程序

doPost() {
    XYDataset xyDataset = Chart.createDataset(chartType, getServletContext());
    JFreeChart chart = Chart.createChart(xyDataset, chartType);
    final ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());
    final File file1 = new File("D:\\graph\\test.png");
    ChartUtilities.saveChartAsPNG(file1, chart, 600, 400, info);

    // write an HTML page incorporating the image with an image map
    final File file2 = new File("D:\\graph\\multipiechart100.html");
    final OutputStream out = new BufferedOutputStream(new FileOutputStream(file2));
    final PrintWriter writer = new PrintWriter(out);
    writer.println("<HTML>");
    writer.println("<HEAD><TITLE>JFreeChart Image Map Demo</TITLE></HEAD>");
    writer.println("<BODY>");
    //            ChartUtilities.writeImageMap(writer, "chart", info);
    writer.println("<IMG SRC=\"multipiechart100.png\" "
        + "WIDTH=\"600\" HEIGHT=\"400\" BORDER=\"0\" USEMAP=\"#imageMap\">");
    writer.println("</BODY>");
    writer.println("</HTML>");
    writer.close();

    BufferedImage buf = chart.createBufferedImage(800, 450, info);
    ChartUtilities.writeImageMap(writer, "imageMap", info, true);
    //          ChartUtilities.writeBufferedImageAsPNG(out,buf);
    ChartUtilities.writeChartAsPNG(out, chart, 700, 250, info);
}

JSP:

<img alt="" id="monthchart" usemap="#imageMap"
                            src='<%=url+"/TimeChart/servlet/ChartServlet?CHARTTYPE="+ChartConstant.MONTH_CHART%>'></img>

但我没有得到任何图表,并且出现如下错误:

java.io.IOException: Write error
    at java.io.FileOutputStream.writeBytes(Native Method)
    at java.io.FileOutputStream.write(FileOutputStream.java:260)
    at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:65)
    at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:123)
    at javax.imageio.stream.FileCacheImageOutputStream.close(FileCacheImageOutputStream.java:213)
    at javax.imageio.ImageIO.write(ImageIO.java:1567)
    at org.jfree.chart.encoders.SunPNGEncoderAdapter.encode(SunPNGEncoderAdapter.java:127)
    at org.jfree.chart.encoders.EncoderUtil.writeBufferedImage(EncoderUtil.java:134)
    at org.jfree.chart.ChartUtilities.writeChartAsPNG(ChartUtilities.java:185)
    at com.chart.ChartServlet.doPost(ChartServlet.java:138)
    at com.chart.ChartServlet.doGet(ChartServlet.java:60)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:291)
    at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:877)
    at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:594)
    at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1675)
    at java.lang.Thread.run(Thread.java:619)
4

1 回答 1

0

一方面,您在调用 ChartUtilities.writeImageMap(...); 之前关闭了您的作家。

于 2016-11-25T01:26:31.067 回答