Problem writing chart as PNG when chart has no data.

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
dan1son
Posts: 12
Joined: Thu Jun 29, 2006 7:06 pm
Location: Austin, TX

Problem writing chart as PNG when chart has no data.

Post by dan1son » Fri Oct 17, 2008 8:08 pm

I'm trying to use the nodatamessage to show an empty chart when there is no data. When I call ChartUtilities.writeChartAsPNG(outputStream, chart, 1024, 768) I get an IOException.

This same output code works fine when the chart contains data.

Code:

Code: Select all

        JFree Chartchart = ChartFactory.createTimeSeriesChart(_jobName,
                "Time",
                "",
                new TimeSeriesCollection(new TimeSeries("")),
                false, false, false);
        chart.getXYPlot().setNoDataMessage("No Data Match.");
        

        // Output the PNG chart to the outputstream in the given size
        try {
            ChartUtilities.writeChartAsPNG(this.getOutputStream(), chart, 1024, 768);
            this.getOutputStream().close();
        } catch (IOException e) {
            e.printStackTrace();
        }
Exception:

Code: Select all

javax.imageio.IIOException: I/O error writing PNG file!
    [jetty] 13:58:10.917 [qtp0-2] ERROR STDERR - 	at com.sun.imageio.plugins.png.PNGImageWriter.write(PNGImageWriter.java:1152)
    [jetty] 13:58:10.918 [qtp0-2] ERROR STDERR - 	at javax.imageio.ImageWriter.write(ImageWriter.java:598)
    [jetty] 13:58:10.918 [qtp0-2] ERROR STDERR - 	at javax.imageio.ImageIO.write(ImageIO.java:1479)
    [jetty] 13:58:10.918 [qtp0-2] ERROR STDERR - 	at javax.imageio.ImageIO.write(ImageIO.java:1565)
    [jetty] 13:58:10.918 [qtp0-2] ERROR STDERR - 	at org.jfree.chart.encoders.SunPNGEncoderAdapter.encode(SunPNGEncoderAdapter.java:127)
    [jetty] 13:58:10.918 [qtp0-2] ERROR STDERR - 	at org.jfree.chart.encoders.EncoderUtil.writeBufferedImage(EncoderUtil.java:134)
    [jetty] 13:58:10.918 [qtp0-2] ERROR STDERR - 	at org.jfree.chart.ChartUtilities.writeChartAsPNG(ChartUtilities.java:185)
    [jetty] 13:58:10.918 [qtp0-2] ERROR STDERR - 	at org.jfree.chart.ChartUtilities.writeChartAsPNG(ChartUtilities.java:136)
Further information. Sorry it took a bit, got shoved into a meeting...
Basically the correct looking empty chart is put to the outputstream, but after that an IOException is thrown, which is causing issues on my server. When the chart has data, it is written to the outputstream and no exception is thrown.

Any ideas on what to look at? I'd expect an empty chart (where the noDataMessage is used) to be put on the outputstream with no exception just like a filled chart.

Thanks,
Dan

Locked