Hi all, By default the quality of the rendered charts is too bad to be usable when a JasperReport is exported in XLS, PPT,... I found a possible solution in www.jasperforge.org/plugins/espforum/view.php but the problem with this solution is that all charts are rendered as bitmap images, even when exported to PDF. I needed a solution that allows the chart to be redered in : a "vector" format (ie DRAW) when exported to PDF a good quality bitmap when exported to XLS, PPT,...The solution I found (inspired by the one of rckrll106) is to enhance the getImageData() of the net.sf.jasperreports.engine.JRAbstractSvgRenderer class : public byte[] getImageData() throws JRException {
Dimension2D dimension = getDimension();
if (dimension != null) {
int imageDPI = JRProperties.getIntegerProperty("net.sf.jasperreports.svgrenderer.chart.dpi", 72);
double scale = ((double) imageDPI) / 72d; byte imageType = getImageType();
BufferedImage bi =
new BufferedImage(
(int) (scale * dimension.getWidth()),
(int) (scale * dimension.getHeight()),
// avoid creating JPEG images with transparency that would result
// in invalid image files for some viewers (browsers)
(imageType == JRRenderable.IMAGE_TYPE_GIF || imageType == JRRenderable.IMAGE_TYPE_PNG)
? BufferedImage.TYPE_INT_ARGB : BufferedImage.TYPE_INT_RGB
); Graphics2D g = createGraphics(bi);
g.scale(scale, scale);
Color backcolor = getBackcolor();
if (backcolor != null) {
g.setColor(backcolor);
g.fillRect(0, 0, (int) (scale * dimension.getWidth()), (int) (scale * dimension.getHeight()));
}
render(g, new Rectangle((int) dimension.getWidth(), (int) dimension.getHeight()));
g.dispose(); return JRImageLoader.loadImageDataFromAWTImage(bi, getImageType());
}
return null;
} You can then change the quality of the rendered charts by adding - in the jasperreports.properties - the net.sf.jasperreports.svgrenderer.chart.dpi property and setting it to (for example) 200. What do you think about this solution ? Is there any chance to integrate it in one of the next releases of JasperReports ? Regards, Phil Post Edited by phgaudin at 05/25/2011 05:58