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

Change range of y-axis


akhanh

Recommended Posts

Hi,

 

i tried to change the range y-axis of a bar-chart.

i create a

'class customizer implements JRChartCustomizer'

a i tried to use it with

' // getchart

JRDesignChart i = (JRDesignChart) (jdesgn.getSummary().getElements()[0]);

i.setCustomizerClass(new customizer().toString());

'

but it do not work.

 

What i should write in

i.setCustomizerClass(new customizer().toString());

 

Thanks

Ali Baba

Link to comment
Share on other sites

  • Replies 8
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

I'm not sure how you get the particular properties that you are looking to modify. I've modified different properties. I've posted the class and method that I used. Hopefully this will give you a starting point to work from.

 

Code:


public class JasperChartCustomizer extends JRAbstractChartCustomizer
{

public void customize(JFreeChart chart, JRChart jasperChart)
{
//Chart is a bar chart
if(jasperChart.getChartType() == JRChart.CHART_TYPE_BAR)
{ }

}
}
Link to comment
Share on other sites

HI,

this could work, but my problem is to set the customizer class.

I have a custumizer extends JRAbstractChartCustomizer

and i try to use it with

JRDesignChart i = (JRDesignChart) (jdesgn.getSummary().getElements()[0]);

i.setCustomizerClass("customizer");

but i get

Exception in thread "main" net.sf.jasperreports.engine.JRRuntimeException: Could not create chart customizer instance.

 

i dont know i set the customizer class...

Link to comment
Share on other sites

Hi,

that works very fine.

 

For all a summary:

1.

create:

package tests;

 

import net.sf.jasperreports.engine.JRAbstractChartCustomizer;

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

import org.jfree.data.Range;

 

public class customizer extends JRAbstractChartCustomizer{

 

public void customize(JFreeChart jfreechart, JRChart arg1) {

// Get the plot

CategoryPlot plot = jfreechart.getCategoryPlot();

plot.getRangeAxis().setRange(10, 100);

}

 

}

 

2.: set it (see last post) in the chart the customizer class.

In my example you must write tests.customize

tests is the package name.

 

Thats all and you get a y-axis range from 10 to 100.

With the methods of plot (see above) you can change

different values of the chart

 

Ali Baba

Link to comment
Share on other sites

Hi,

that works very fine.

 

For all a summary:

1.

create:

package tests;

 

import net.sf.jasperreports.engine.JRAbstractChartCustomizer;

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

import org.jfree.data.Range;

 

public class customizer extends JRAbstractChartCustomizer{

 

public void customize(JFreeChart jfreechart, JRChart arg1) {

// Get the plot

CategoryPlot plot = jfreechart.getCategoryPlot();

plot.getRangeAxis().setRange(10, 100);

}

 

}

 

2.: set it (see last post) in the chart the customizer class.

In my example you must write tests.customize

tests is the package name.

 

Thats all and you get a y-axis range from 10 to 100.

With the methods of plot (see above) you can change

different values of the chart

 

Ali Baba

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