1

I'm creating a chart in a servlet, and it works great.

chart = ChartFactory.createPieChart("Smart Chart", ds, true, true,
                true);
        PiePlot plot = (PiePlot) chart.getPlot();
        ImageIcon icon = new ImageIcon(bgImageStr);

        plot.setBackgroundPaint(Color.CYAN);
        plot.setBackgroundAlpha(0.15f);

        chart.setBackgroundPaint(Color.WHITE);
        chart.getTitle().setBackgroundPaint(Color.PINK);
        chart.setBackgroundImage(icon.getImage());

Problem is, the background image is not showing up. I've tried the plot and chart bg, and all kinds of other stuff. It must be simple, anyone see what is wrong? I'm just using the write to PNG to dump it to the browser. It shows up fine, with all the color changes, just no image.

mikeb
  • 10,578
  • 7
  • 62
  • 120
  • Do you know for a fact that the image exists, that your path to the image file is correct? Also, often it is better to use resources rather than files. – Hovercraft Full Of Eels Aug 11 '13 at 21:53
  • `bgImageStr` should be a file name, is it or is it not? – tbodt Aug 11 '13 at 21:53
  • YbgImageStr is a filename, and it does exist (if I dump the image to the output stream instead of the chart, the image displays in the browser) – mikeb Aug 11 '13 at 22:27

2 Answers2

0

OK, OP here, I fixed it.

I was calling the servlet from itself, and it did not like that. I used a resource (as suggested) and it worked fine without the infinite recursion (imagine that).

mikeb
  • 10,578
  • 7
  • 62
  • 120
-1

apply try{ Thread.sleep(100); } catch(InterruptedException IntExp) { //your implementation } before chart.setBackgroundImage(icon.getImage());

Omar Bahir
  • 1,237
  • 5
  • 20
  • 48