0

I print a jfreechart on Internet Explorer and i got a blank page. Actually, the version of my IE is 11.0.9600.18697CO, 11.0.43 (KB4021558).

I hadn't this problem with older version IE.

I haven't this problme on Chrome and Firefox.

My freechart is generated on the server, showed on the client by a servlet and deleted on the server (it is a jfreechart-one time]).

On the console debug of IE, when i execute window.print(); there are requets sended to server. I think it caused problem (although http code = 200).

If i don't delete the chart on the server, i have no problem.

Someone hit the same problem? Solution? thanks a lot, best regards

dsea
  • 75
  • 3
  • 16

1 Answers1

1

In a servlet context using ChartUtilities, instead of using one of the save… methods, try using the corresponding write… method.

public void doGet(HttpServletRequest request, HttpServletResponse response) throws … {
    OutputStream out = response.getOutputStream();
    …
    //ChartUtilities.saveChartAsPNG(file, chart, …);
    ChartUtilities.writeChartAsPNG(out, chart, …);
}

Could you explain why? I am using ServletUtilities.saveChartAsPNG()

I'm guessing that there's a race condition that allows the file to be deleted prematurely. If you need the ChartRenderingInfo, the corresponding ChartUtilities method would likely be writeChartAsPNG(). If you can't switch, use a DelayQueue<File> to defer deleting the temporary file.

trashgod
  • 203,806
  • 29
  • 246
  • 1,045
  • could you explain why? I am using [http://www.jfree.org/jfreechart/api/javadoc/org/jfree/chart/servlet/ServletUtilities.html#saveChartAsPNG-org.jfree.chart.JFreeChart-int-int-org.jfree.chart.ChartRenderingInfo-javax.servlet.http.HttpSession-]ServletUtilities.saveChartAsPNG – dsea Jul 10 '17 at 13:44
  • I've elaborated above. – trashgod Jul 11 '17 at 11:16
  • I can't switch ServletUtilities.saveChartAsPNG to ChartUtilities.writeChartAsPNG because i do the graph and show it in one jsp file, with tag, eg, – dsea Jul 12 '17 at 06:47
  • The `src` doesn't have to be a file; if can be a servlet, for [example](https://stackoverflow.com/q/9835061/230513). – trashgod Jul 12 '17 at 09:22