Jasper reports 如何使用iReport 4.5.1中的条形图绘制一个月的每日报告?

Jasper reports 如何使用iReport 4.5.1中的条形图绘制一个月的每日报告?,jasper-reports,ireport,Jasper Reports,Ireport,我们使用iReport工具创建jrxml 假设我们有db表,其中包含每天的信息(日期作为一列) 假设我们在4月10日(4月10日)生成4月的每日报告 我们确实看到我的条形图(x轴->日,y轴->值数据)生成,但x轴范围仅显示从1到10 但我们希望看到x轴的范围从1到30,并且仅在前10天内进行涂漆 上面的原因是我们已经为这个x轴映射了日期字段(我们的数据库只有10号之前的数据)。但根据我对ireport工具的了解,我不确定如何实现这一点 欢迎使用iReport获得任何帮助 谢谢, Senthil

我们使用iReport工具创建jrxml

假设我们有db表,其中包含每天的信息(日期作为一列)

假设我们在4月10日(4月10日)生成4月的每日报告

我们确实看到我的条形图(x轴->日,y轴->值数据)生成,但x轴范围仅显示从1到10

但我们希望看到x轴的范围从1到30,并且仅在前10天内进行涂漆

上面的原因是我们已经为这个x轴映射了日期字段(我们的数据库只有10号之前的数据)。但根据我对ireport工具的了解,我不确定如何实现这一点

欢迎使用iReport获得任何帮助

谢谢,
Senthil VS

您需要为此创建一个图表自定义程序,并将图表自定义程序类分配给您的TimeSeries图表

这是图表自定义程序的代码,用于实现您所需的功能:

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) {
                // 
            }
        }
    }

}
问候


朱利奥

谢谢朱利奥。我将在本地进行测试,并很快更新这个线程。@Giulio:你能解释一下如何使用这些图表定制器类吗?因为我对Java一无所知。