Search code examples
htmlsvgjasper-reports

JasperReports - Embedding chart as SVG into HTML report


I'm using JasperReports integrated into Spring application (JasperReports 6.3.0, SpringBoot 1.4.1).

I have a report (created with Jaspersoft Studio 6.3.1) with a stacked bar chart within. It does print properly in pdf, xls. The problem is html format, which has the chart displayed as an empty box - when you look at the source code, the src attribute of img element is empty.

I've seen people advicing setting up some kind of Jasper-defined servlet to serve images as static files to html report, though this might be extra complicated with environment I'm working on.

The most convenient way I can think of is to insert the chart in svg format, so that it would be present inside the html content - this is my preferred solution to this.

The chart element (in report desing) actually has an option to be displayed as svg, though changing this doesn't seem to affect html output at all, just like Jasper would want to export the created svg to a file, and then include it as image anyways.

I've tried several config options, but I'm kind of stuck now, so my question is:

Do I need some extra environment setup, or some other fancy stuff, to reach my goal? Is what I ask for even possible with JasperReports?

Thanks in advance!


Solution

  • What you need is the following two properties in your jasperreports.properties (if you don't already have that file, create it and put it to a jar or folder that's on the application classpath):

    net.sf.jasperreports.chart.render.type=svg
    net.sf.jasperreports.export.html.embed.image=true