Jump to content
We've recently updated our Privacy Statement, available here ×

Chart customize


Muyerina

Recommended Posts

Hello everybody:

 

I'm having problems with my chart customizer using i-Report.

 

My class 'GraficoChartCustomizer' compile and i-Report can recognise it when i specify it in the chart properties, but i-Report ignore the changes i do in the class, the graphic seems equal.

 

Anyone can help me? All i want to do is change the font of the rectangle's label.

 

size=300]http://i22.photobucket.com/albums/b320/Muyerina/untitled.jpg

 

My customize class is the following:

Code:

Thank you

Link to comment
Share on other sites

  • Replies 6
  • Created
  • Last Reply

Top Posters In This Topic

hi Muyerina!

i have seen the image u had posted.... i m getting a problem of showing the lables inside the bars of the barChart... by default ireport shows the label expression as

 

Chart position

______________________________

BarChart : top of the bars

3DBar : inside top of bars

_______________________________

 

can you please help me in showing the lable expression of 3DBarChart on the top of the bars! further more how come customizer class can help me in this regard? and how does it works?

thnks alot in adv.

Post edited by: mbj_ravian, at: 2008/04/30 16:17

Link to comment
Share on other sites

  • 2 weeks later...

This is an example of a chart customizer I have working, I jar up the class and add a classpath in ireports.

eg: Options->Classpath->Add jar

 

and viola it works like a charm.

 

Code:
public class BillingChartCustomerizer implements JRChartCustomizer
{
public void customize(final JFreeChart chart, final JRChart jasperChart)
{
final GroupedStackedBarRenderer renderer = new GroupedStackedBarRenderer();
final KeyToGroupMap map = new KeyToGroupMap("C1"«»);
map.mapKeyToGroup("group1", "C1"«»);
map.mapKeyToGroup("group2", "C1"«»);
map.mapKeyToGroup("group3", "C2"«»);
renderer.setSeriesToGroupMap(map);
renderer.setItemMargin(0.0);

final CategoryPlot plot = (CategoryPlot) chart.getPlot();
plot.setAxisOffset(RectangleInsets.ZERO_INSETS);
plot.setRenderer(renderer);
}
}
Link to comment
Share on other sites

greylimbo, thanks a lot for your customizer class.

 

Now it seems that the iReport do the changes of my customizer class, but the label of the rectangles has disapeared. Why? i dont know :dry:

 

my new code:

Code:
StackedBarRenderer renderer = new StackedBarRenderer();
renderer.setItemMargin(0.9);
renderer.setBaseItemLabelFont(new Font("Sans", Font.PLAIN, 6));

CategoryPlot plot = (CategoryPlot) chart.getPlot();
plot.setRenderer(renderer);

 

I tried a lot of methods (setBaseItemLabelFont, setSeriesItemLabelFont, setFixedLegendItems...) but no one works.

 

Anyone can help me?

Link to comment
Share on other sites

I've found it!!!

 

This is the code of my Customize class that modify the item label of a rectangle in a StackedBarChart.

 

Code:

import net.sf.jasperreports.engine.JRChartCustomizer;
import net.sf.jasperreports.engine.JRChart;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.renderer.category.StackedBarRenderer;

import java.awt.*;

import org.jfree.chart.plot.CategoryPlot;

public class GraficoChartCustomizer implements JRChartCustomizer
{
protected static final java.awt.Font ITEM_FONT = new java.awt.Font("Arial", Font.ITALIC, 6);

public void customize(final JFreeChart chart, final JRChart jasperChart)
{
CategoryPlot plot = chart.getCategoryPlot();
StackedBarRenderer renderer = (StackedBarRenderer) plot.getRenderer();
renderer.setBaseItemLabelFont(ITEM_FONT);
}
}

 

I hope this help you.

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