Jump to content

JASPER report chart label


sanathk

Recommended Posts

Hi All can one of you guys help me. I have developed few jasper reports and all of them consists of 2 charts.I wanted them to be small in size but their lables are very big. How can I reduce this lable size. Is there any way to reduce the font size of the lables of the chart. (am using a pie chart)

 

Here is my code in jrxml to represent the chart.

*************************************************

**************************************************

Code:
<pieChart>
<chart hyperlinkTarget="Self" >
<reportElement
x="6"
y="33"
width="257"
height="188"
key="element-1"/>
<box topBorder="None" topBorderColor="#000000" leftBorder="None" leftBorderColor="#000000" rightBorder="None" rightBorderColor="#000000" bottomBorder="None" bottomBorderColor="#000000"/>

</chart>
<pieDataset>
<dataset resetType="None" >
</dataset>
<keyExpression><![CDATA[$F{gender}]]></keyExpression>
<valueExpression><![CDATA[$F{killed}]]></valueExpression>
<labelExpression><![CDATA[$F{gender}]]></labelExpression>

</pieDataset>
<piePlot>
<plot />
</piePlot>
</pieChart>
<line direction="TopDown">
<reportElement
x="4"
y="5"
width="522"
height="0"
key="line-3"/>
<graphicElement stretchType="NoStretch"/>
</line>
<pieChart>
<chart hyperlinkTarget="Self" >
<reportElement
x="273"
y="34"
width="250"
height="187"
key="element-2"/>
<box topBorder="None" topBorderColor="#000000" leftBorder="None" leftBorderColor="#000000" rightBorder="None" rightBorderColor="#000000" bottomBorder="None" bottomBorderColor="#000000"/>

</chart>
<pieDataset>
<dataset resetType="None" >
</dataset>
<keyExpression><![CDATA[$F{gender}]]></keyExpression>
<valueExpression><![CDATA[$F{wounded}]]></valueExpression>
<labelExpression><![CDATA[$F{gender}]]></labelExpression>

</pieDataset>
<piePlot>
<plot />
</piePlot>
</pieChart>
Link to comment
Share on other sites

  • Replies 4
  • Created
  • Last Reply

Top Posters In This Topic

I had the same problem. You can't do it with JasperReports, unless you make some modifications :

Import the JasperReports source code as a project into Eclipse (or another IDE), open the file net/sf/engine/fill/JRFillChart, search for the method "evaluatePieImage", and replace the line :

 

piePlot.setLabelFont(new Font(JRFontUtil.getAttributes(new JRBaseFont(null, null, this, null))));

 

by something like this :

 

piePlot.setLabelFont(new Font("Serif", Font.PLAIN, font_size));

 

With font_size being the size you want to use.

Then compile and recreate the jars using Ant (choose the target named "jar"), and finally put the newly generated jar where you want to use it. (eg : the lib/ directory in IReport)

 

I really hope that the JasperReports developers will integrate this though, because this is an annoying problem...

Link to comment
Share on other sites

  • 1 month later...

I found that I could modify the label font by using a JRChartCustomizer class.. here's my simple implementation below:

 

Code:

public class ChartLabelCustomizer implements JRChartCustomizer {

public void customize(JFreeChart chart, JRChart jasperChart) {
// Check the type of plot..
Plot plot = chart.getPlot();
if(plot instanceof PiePlot){
PiePlot piePlot = (PiePlot) plot;
piePlot.setLabelFont(new Font("SanSerif",Font.PLAIN,8));
}
}
}

 

 

This should help you customize without resorting to modifying and recompiling the default JasperReports library..

 

Cheers,

Jamie

Link to comment
Share on other sites

If you are using something like eclipse, the java will always compile automatically. Create a new class in whatever package you want. Export the package to a jar into any java lib directory (ie ireport lib directory or jre ext directory). When Jasper looks for the customizer class, it should find it in the lib you exported.
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...