Jump to content
Changes to the Jaspersoft community edition download ×

labels in bar charts are cut


jeipack

Recommended Posts

  • Replies 5
  • Created
  • Last Reply

Top Posters In This Topic

  • 6 months later...

Hey I know this is an old post but for anyone else looking to do this, use a chart customizer w/:

Code:

CategoryPlot plot = chart.getCategoryPlot();
cata.setMaximumCategoryLabelWidthRatio(2f);

or

Code:
[code]
CategoryPlot plot = chart.getCategoryPlot();
cata.setMaximumCategoryLabelLines(2);

 

Hope this helps someone.

Link to comment
Share on other sites

This may be a stupid question but can you give a full example of how to do that in the customize() function? I have a good idea but I'm still learning how to customize through iReport. Speaking of which, where would I put my class once it's compiled, and how would I tell my chart in iReport where to find it?
Link to comment
Share on other sites

  • 3 weeks later...

It's not a stupid question at all. Sometimes even when you understand the idea perfectly it can be tough to get all of the details exactly correct. Here are my notes from creating a chart customizer that allows long category labels.

 

1. mkdir com/jaspersoft/demo

2. create the chart customizer in the demo directory (code below)

3. set CLASSPATH=%CLASSPATH%;C:/JasperSoft/iReport-2.0/lib/jasperreports-2.0.2.jar

4. set CLASSPATH=%CLASSPATH%;C:/JasperSoft/iReport-2.0/lib/jfreechart-1.0.0.jar

5. javac -target 1.5 -source 1.5 com/jaspersoft/demo/MyChartCustomizer.java

6. jar -cf MyCustomizers.jar com

 

Now you have a jar file that contains your compiled chart customizer. To run the report in iReport you can add MyCustomizers.jar to the classpath with the menu Options->Classpath. (It will pick the .jar file up automatically if it's in the working directory. But I recommend setting it explicitly to be clear.)

 

To run the report in JasperServer just upload the .jar file and then add a reference on the Report Unit to it.

 

I hope my notes will be useful for someone.

 

-Matt

Code:

package com.jaspersoft.demo;
/**
*
* @author gtoffoli
* Modified 19 Aug 2007 by mdahlman
*
*/
import net.sf.jasperreports.engine.JRChart;
import net.sf.jasperreports.engine.JRChartCustomizer;

import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.plot.XYPlot;

import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.renderer.category.BarRenderer;
import org.jfree.chart.axis.CategoryAxis;

public class BarLabels implements JRChartCustomizer {


public void customize(JFreeChart jFreeChart, JRChart jrChart) {

CategoryPlot plot = jFreeChart.getCategoryPlot();
BarRenderer renderer = (BarRenderer) plot.getRenderer();
CategoryAxis axis = plot.getDomainAxis();
axis.setMaximumCategoryLabelWidthRatio(1.5f);
}

}

Post edited by: mdahlman, at: 2007/10/24 21:02

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...