I am new to JasperReports and slowly struggling with my fundamentals. I have a situation where I do not want to fill the pie chart with database-driven data (through a so-called data source). I want to provide all the information needed to populate a pie chart from a Java hash map passed to JasperFillManager at runtime.
This will include parameters for marking slices in a pie chart, setting their colors and determining their weights / values (slicing size). So, at some point in my Java code, I would write something like:
HashMap<String,Object> jrParams = new HashMap<String,Object>();
jpParams.put("slice_1_label", "Red Team");
jpParams.put("slice_1_color", Color.RED);
jpParams.put("slice_1_value", 67.0);
jpParams.put("slice_2_label", "Blue Team");
jpParams.put("slice_2_color", Color.BLUE);
jpParams.put("slice_2_value", 33.0);
JasperFillManager.fillReport(jasperDesign, jrParams);
The goal I am trying to achieve here is to have a 2-sliced pie chart; the red slice of the Red Team, which occupies 67% of the pie, and the blue “blue team”, which gained 33%.
Now I need help connecting the dots between my hashmap and JRXML / JasperDesign.
Can someone show me (or just help me help) regarding which <pieChart>JRXML I need to write so that my hash file jrParamfills the pie chart with runtime parameters? I made a better attempt below, but I'm just struggling to fully understand all this.
<pieChart>
<chart isShowLegend="true">
<reportElement x="10" y="10" width="300" height="300"/>
<chartTitle>
<titleExpression><![CDATA[My First JR Pie Chart]]></titleExpression>
</chartTitle>
</chart>
<pieDataset>
</pieDataset>
<piePlot>
<plot backcolor="#8BA870"/>
<itemLabel color="#000000"/>
</piePlot>
</pieChart>
Thanks in advance for your help / clarification!