senthil kumar vs
senthil kumar vs

Reputation: 1

how to plot Daily Report of a month using bar chart in iReport 4.5.1?

We use iReport tool for creating jrxml

Assume ,we have db table with info for each day(date as one column)

Say if we go for generation of daily report for month april on 10th (of April).

We do see my bar chart(xaxis->day,y-axis->valuedata) generated but x-axis range shows from 1 till 10 only.

But we wish to see the x-axis range from 1 till 30th and bar painted for first 10 days only.

The reason for the above is we have mapped date field for this x-axis(and our db has only the data till 10th). but i am not sure how to achieve this ,from my knowledge on this ireport tool

Any help to get this achieved using iReport is welcome.

Thanks, Senthil VS

Upvotes: 0

Views: 1126

Answers (1)

Giulio
Giulio

Reputation: 91

You need to create a chart customizer for that, and assign the Chart customizer class to your TimeSeries chart.

This is the code of a chart customizer to achieve what you need:

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.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 gtoffoli
 */
public class DateRangeCustomizer implements JRChartCustomizer {

    @Override
    public void customize(org.jfree.chart.JFreeChart jfc, JRChart jrc) {



        XYPlot plot = jfc.getXYPlot();


        ValueAxis axis = plot.getDomainAxis();


        if (axis instanceof DateAxis)
        {
            DateAxis daxis = (DateAxis)axis;


            try {

                // Here you can find your way to set the range... i.e. you may get the current available range and try
                // to guess the current month...

                daxis.setRange( new SimpleDateFormat("yyyy/MM/dd").parse("2012/03/01"),  new SimpleDateFormat("yyyy/MM/dd").parse("2012/03/31"));
                daxis.setAutoRange(false);
            } catch (ParseException ex) {
                // 
            }
        }
    }

}

Regards

Giulio

Upvotes: 1

Related Questions