nico-uk Posted August 21, 2014 Share Posted August 21, 2014 Hi,I'm using JasperSoft studio and 5.6.0 JasperReports libraries. I want to customize my chart with a customizer but it does not work properly.I have a barchart (or stacked) that is evaluated at group time. The barchart can have more or less categories than the others.So I wanted to resize my chart included in the report with a customizer which calculate the suited size. Solution : I call the method setWidth() on the JRChart object. But the fact is that the customizer shifts the result, the chart of a group got the width intended for the chart of the previous group.The final result gives : - The first chart got the initial width designed in the report although the method setWidth() is called at the right time...- The second chart got the width intended for the first chart, etc... I tried to fix a size in the method setWidth(), but it shifts the first chart, it has the initial width designed in the report.I think the method is applied on the "theme" of the chart and not on the instance. Why the customizer does not work properly ? Is it the engine or something else ? Is there another way to do it (the resize of the chart)? XML Chart included in the JasperReport : <multiAxisChart> <chart evaluationTime="Group" evaluationGroup="NameGroup" customizerClass="MRChartCustomizer"> <reportElement x="0" y="49" width="2000" height="291" printWhenGroupChanges="NameGroup" uuid="176df2f9-bb95-4d5e-8049-82d37389bcca"> <property name="local_mesure_unitwidth" value="pixel"/> <property name="com.jaspersoft.studio.unit.width" value="px"/> </reportElement> <chartTitle/> <chartSubtitle/> <chartLegend/> </chart> <multiAxisPlot> <plot backgroundAlpha="1.0" foregroundAlpha="1.0"/> <axis> <stackedBarChart> <chart evaluationTime="Group" evaluationGroup="NameGroup"> <reportElement x="0" y="0" width="0" height="0" backcolor="#FFFFFF" uuid="61353557-f184-4f76-b3e4-d0c454925ca0"/> <chartTitle color="#000000"/> <chartSubtitle color="#000000"/> <chartLegend textColor="#000000" backgroundColor="#FFFFFF"/> </chart> <categoryDataset> <dataset resetType="Group" resetGroup="NameGroup"/> <categorySeries> <seriesExpression><![CDATA["Series"]]></seriesExpression> <categoryExpression><![CDATA[$F{category}]]></categoryExpression> <valueExpression><![CDATA[$F{value}]]></valueExpression> <labelExpression><![CDATA["Label"]]></labelExpression> </categorySeries> </categoryDataset> <barPlot> <plot/> <itemLabel/> <categoryAxisFormat> <axisFormat verticalTickLabels="true"/> </categoryAxisFormat> <valueAxisFormat> <axisFormat/> </valueAxisFormat> </barPlot> </stackedBarChart> </axis> </multiAxisPlot> </multiAxisChart>[/code] Method customize() of the customizer @Override public void customize(JFreeChart chart, JRChart jasperChart) { // Get the plot CategoryPlot plot = chart.getCategoryPlot(); // Set the width jasperChart.setWidth(plot.getCategories().size() * 10); }[/code] Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now