JFreeChart low performance for MeterPlot

0

I'm implementing a web application using spring 4.2.5 and jasperreports 6.4.3.
This app is supposed to generate a pdf file as output. There are three jrxml files:
 
1. firstpage.jrxml: contains logo and some titles

2. intro.jsrxml: contains some texts and a table of items overview

3. items.jrxml: contains some texts and an image to show a JFree MeterPlot output buffer image.

**The code:**

    public void export() {    
        JasperPrint firstPagePrint = ...;    
        JasperPrint introPrint = ...;    
        List<JasperPrint> itemsPrints = new LinkedList<JapserPrint>();    
        List<Item> items = ...;    
        for (int i = 0; i < items.size(); i++) {
           Item item = items.get(i);
           MeterPlot meterPlot = new MeterPlot(new DefaultValueDataset(item.getValue()));
           meterPlot.setRange(new Range(item.getMinValue(), item.getMaxValue()));
           meterPlot.addInterval(new MeterInterval("bad", new Range(item.getMinValue(), item.getSect1()),
                                    Color.red, new BasicStroke(2f), Color.red));
           meterPlot.addInterval(new MeterInterval("weak", new Range(item.getSect1(), item.getSect2()),
                                    Color.orange, new BasicStroke(2f), Color.orange));
           meterPlot.addInterval(new MeterInterval("average", new Range(item.getSect2(), item.getSect3()),
                                    Color.yellow, new BasicStroke(2f), Color.yellow));
           meterPlot.addInterval(new MeterInterval("good", new Range(item.getSect3(), item.getSect4()),
                                    Color.green, new BasicStroke(2f), Color.green));
           meterPlot.addInterval(new MeterInterval("excellent", new Range(item.getSect4(), item.getMaxValue()),
                                    Color.black, new BasicStroke(2f), Color.BLUE));
 
           JFreeChart jFreeChart = new JFreeChart(item.getTitle(), meterPlot);
           BufferedImage bufferedImage = jFreeChart.createBufferedImage(555, 250);
           String tmpFile = FileService.JASPER + Util.randomNumeralString(20) + ".png";
           ImageIO.write(bufferedImage, "png", new File(tmpFile));
           itemAnalysisParams.put("chartImage", tmpFile);
           analysisPrints.add(JasperFillManager.fillReport(ITEM_ANALYSIS, itemAnalysisParams, new JREmptyDataSource()));
       }
 
       ...export pdf by jasper report prints
 
    }

**Notice:**

sect1, sect2, sect3 and sect4 are internal limitation for intervals.

    sect = (maxValue - minValue) * 20 / 100
    sect1 = this.minValue + sect
    sect2 = this.sect1 + sect
    sect3 = this.sect2 + sect
    sect4 = this.sect3 + sect

The problem:

The line

BufferedImage bufferedImage = jFreeChart.createBufferedImage(555, 250);

takes a long time- about 15min- to create image and it repeats for about 45 items and takes 15min*45 total time to generate report.

In advance, I appreciate any help.

babak_behzadi's picture
Joined: Dec 19 2017 - 11:15am
Last seen: 2 years 10 months ago

0 Answers:

No answers yet
Feedback
randomness