custom chart

0

Hi all;

 

i've created a chart ; and i want to add units to x and Y axis; and also i've another problem withdisplayed  X axis( datetime)  values  that i want to custom to display valeur each  15 days.

jb0elec's picture
Joined: Apr 2 2013 - 11:58am
Last seen: 8 years 1 week ago

1 Answer:

0

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. 
vitthal_vitthal's picture
Joined: Nov 11 2013 - 9:28pm
Last seen: 5 years 11 months ago
Feedback