I am brand new to JasperReports and am slowly fighting my way through the basics. I have a situation where I do not want to fill a pie chart with DB-driven data (through a so-called datasource). I want to supply all the information necessary to fill the pie chart from a Java hashmap passed into the JasperFillManager at runtime.
This would include parameters to label the slices in the pie chart, set their colors, and define their weights/values (size of the slices). So, at some point in my Java code, I would be writing 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);
// ... some other code
JasperFillManager.fillReport(jasperDesign, jrParams);
The goal I am trying to achieve here would be to have a pie chart with 2 slices; a red "Red Team" slice taking up 67% of the pie, and a blue "Blue Team" slice takig up 33%.
I now need help "connecting the dots" between my hashmap and the JRXML/JasperDesign.
Can someone either show me (or just help guide me) towards what sort of <pieChart>
JRXML I would need to write in order to have my jrParam
hashmap fill the pie chart with runtime parameters? I have made a best-attempt below but am just struggling on making total sense of it all.
<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>
<!-- Here is where I believe I need to put my two slices; not sure how -->
</pieDataset>
<piePlot>
<plot backcolor="#8BA870"/>
<itemLabel color="#000000"/>
</piePlot>
</pieChart>
Thanks in advance for any help/clarification!