Jump to content
Changes to the Jaspersoft community edition download ×

custom chart


jb0elec

Recommended Posts

  • 8 months later...
  • Replies 1
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Hi,

You have to write Chart customizer class and have to call that class from iReport. Please find the below steps to achive this 

1:Write chart customizer class java code(You can use Eclipes or netbean)

2: Make a jar file.

3:Add that jar file in iReport as well in Jasper Server.

4: Call the class from the properties of Vertical Bar Chart in customizer class.

 

Write a Java code in Eclips or Netbean:

package com.TestExample;
 
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import net.sf.jasperreports.engine.JRChart;
import net.sf.jasperreports.engine.JRChartCustomizer;
import org.jfree.chart.axis.DateAxis;
import org.jfree.chart.axis.DateTickUnit;
import org.jfree.chart.axis.ValueAxis;
import org.jfree.chart.plot.XYPlot;
 
/**
 *
 * This chart customizer assumes you are using a TimeSeries Chart.
 * The customization force the use of a different range (i.e. from the start to the end of
 * the month).
 * 
 * author Vitthal Muguli
 
 */
public class TestTick implements JRChartCustomizer {
 
    @Override
    public void customize(org.jfree.chart.JFreeChart jfc, JRChart jrc) {
 
 
 
    DateAxis xAxis = new DateAxis();
    DateTickUnit unit = null; 
            try {
            DateFormat chartFormatter = new SimpleDateFormat("MM/dd/yyyy HH:mm");
                xAxis.setDateFormatOverride(chartFormatter); 
            unit = new DateTickUnit(DateTickUnit.DAY,15); 
                System.out.println("::::::unit:::::"+unit);
                xAxis.setTickUnit(unit);
                xAxis.setVerticalTickLabels(true);
                ((XYPlot)jfc.getPlot()).setDomainAxis(xAxis);
            }
            catch (Exception ex) {
               ex.printStackTrace();
            }
        }
       
    }
 
2 : Make a Jar file
 

Right click on the project and click on clean and build

Net beans will automatically create jar file.

Find this jar file in “dest” folder of your project

3:Add jar file into IReport

 Go to the menu bar

Tools –> Option –> iReport –>Class Path–> Add jar

Select the location of jar file.

 

4 : Call the class from the properties file 
 
Right click on on ur chart and go to properties (right side appears) —> go to customizer class–> in the blank space write the classname including the package.
Example : 
com.TestExample.TestTick
 
Let me know if you have any concern. 
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...