Nikola
Nikola

Reputation: 623

JasperReports SVG chart in HTML report

Is it possible to have sharp or at least not very blurry charts in JasperReports when exported in HTML format?

I use SVG chart renderer type, which is fine for PDF exports. HTML exports remain blurry.

I tried to create SVG programaticaly with JFreeChart and BatikRenderer (using a scriptlet). I get SVG XML which i set as String variable in jrxml file and use it in image element:

<image scaleImage="FillFrame">
    <reportElement positionType="Float" x="401" y="566" width="159" height="124" uuid="1baa80f7-3151-4fb8-be85-140059e9e28e"/>
    <imageExpression>
        <![CDATA[net.sf.jasperreports.renderers.BatikRenderer.getInstanceFromText($V{Chart})]]>
    </imageExpression>
</image>

With this approach image is still blurry (later i noticed all image resources in HTML export are in .png format).

Using code below still generates PNG image in HTML export

net.sf.jasperreports.renderers.BatikRenderer.getInstanceFromText("<svg xmlns:svg=\"http://www.w3.org/2000/svg\" xmlns=\"http://www.w3.org/2000/svg\" version=\"1.0\" width=\"100\" height=\"100\"><circle cx=\"50\" cy=\"50\" r=\"40\" stroke=\"green\" stroke-width=\"4\" fill=\"yellow\" /></svg>")

Is there a way to use generated SVG XML inside of Jasper report or any other solution to get sharp images of charts in HTML file? I was also considering using generated SVG XML inside of TextField component with HTML markup but i don't think that's possible with all HTML tags, just basic ones like <b> and <br>.

Upvotes: 1

Views: 2580

Answers (1)

dada67
dada67

Reputation: 5083

Starting with JasperReports 6.2.2 the HTML exporter will output SVG for chart elements if net.sf.jasperreports.chart.render.type=svg is set, and for BatikRenderer images.

BatikRenderer has actually been deprecated, you can use net.sf.jasperreports.renderers.SimpleDataRenderer.getInstance(byte[]) instead (if you have the SVG as a String you'll need to pass something like $V{Chart}.getBytes("UTF-8")).

For older versions you can improve the quality of the rasterized SVG by setting the net.sf.jasperreports.image.dpi property (in jasperreports.properties) to something like 300. But that would still not be the same as having the actual SVG, so consider upgrading to the latest JasperReports.

Upvotes: 4

Related Questions