1

JFreeChart を使用しており、サーブレット/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

1 つには、ChartUtilities.writeImageMap(...); を呼び出す前にライターを閉じています。

于 2016-11-25T01:26:31.067 に答える