简体   繁体   中英

JfreeChart background image not showing up

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.

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

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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM