Hi
i´m trying to improve the speed performance of rendering barchart inside itextsharp pdf. Actually whene i generate the pdf file it takes about 8secs. here´s some additional data:
- using default barchart, takes about 2secs to generate the pdf.
- using my custom preferences without textures in some bars takes 3.5secs aprox (3.5 secs is not a problem).
- using my custom preferences with textures in some bars takes 7.5 to 8secs aprox.
- textures are png files (400x400 px 300dpi)
any ideas on how can i improve the speed?
thanks in advance
Barchart improvement performance
-
- Posts: 1634
- Joined: Sat Feb 17, 2007 1:51 pm
Re: Barchart improvement performance
Since you haven't posted any code, it is hard to advise.
I assume that the rendering itself is not the issue. At least, I would be surprised to see that the mere drawing of an image with less than 1M pixels takes several seconds.
My guess would be that most of the time is spent in fetching the textures. Running your code with a profiler should answer the question where the time is spent.
I assume that the rendering itself is not the issue. At least, I would be surprised to see that the mere drawing of an image with less than 1M pixels takes several seconds.
My guess would be that most of the time is spent in fetching the textures. Running your code with a profiler should answer the question where the time is spent.
Re: Barchart improvement performance
here´s mi DiffBarRenderer class
and in my class
so if i comment plot.setRenderer... takes 4secs not 8
Code: Select all
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package barchartpdf;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Paint;
import java.awt.Rectangle;
import java.awt.TexturePaint;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.net.URL;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;
import org.jfree.chart.renderer.category.BarRenderer;
import org.jfree.data.category.CategoryDataset;
/**
*
* @author autor
*/
public class DifferenceBarRenderer extends BarRenderer {
public DifferenceBarRenderer() {
super();
}
@Override
public Paint getItemPaint(int x_row, int x_col) {
//getting textures
URL logoUrl2 = DifferenceBarRenderer.class.getResource("/resources/images/pattern.png");
Image img2;
BufferedImage buffered2 = null;
try {
img2 = ImageIO.read(logoUrl2);
buffered2 = (BufferedImage) img2;
} catch (IOException ex) {
Logger.getLogger(DifferenceBarRenderer.class.getName()).log(Level.SEVERE, null, ex);
}
BufferedImage bi2 = new BufferedImage(24, 24,BufferedImage.TYPE_INT_RGB);
Graphics2D big2 = bi2.createGraphics();
Rectangle rn = new Rectangle(0, 0, 24,24);
TexturePaint texture1 = new TexturePaint(buffered2, rn);
URL logoUrl = DifferenceBarRenderer.class.getResource("/resources/images/patten.png");
Image img;
BufferedImage buffered = null;
try {
img = ImageIO.read(logoUrl);
buffered = (BufferedImage) img;
} catch (IOException ex) {
Logger.getLogger(DifferenceBarRenderer.class.getName()).log(Level.SEVERE, null, ex);
}
BufferedImage bi = new BufferedImage(10, 10,
BufferedImage.TYPE_INT_RGB);
Graphics2D big = bi.createGraphics();
Rectangle r = new Rectangle(0, 0, 10,10);
TexturePaint texture2 = new TexturePaint(buffered, r);
CategoryDataset l_jfcDataset = getPlot().getDataset();
switch (x_col) {
case 0:
return texture1;
case 11:
return texture2;
case 12:
return Color.BLACK;
default:
return Color.RED;
}
}
}
Code: Select all
CategoryPlot plot = chart.getCategoryPlot();
plot.setRenderer(new DifferenceBarRenderer());
-
- Posts: 1634
- Joined: Sat Feb 17, 2007 1:51 pm
Re: Barchart improvement performance
As assumed, you are spending far too much time in getting yourt textures.
In every call to getItemPaint(), you are reading ressources from your hard drive. This will seriously slow down the rendering.
Create your TexturePaints once when you create the renderer, and just return them in getItemPaint().
In every call to getItemPaint(), you are reading ressources from your hard drive. This will seriously slow down the rendering.
Create your TexturePaints once when you create the renderer, and just return them in getItemPaint().