【问题标题】:how to plot Daily Report of a month using bar chart in iReport 4.5.1?如何在 iReport 4.5.1 中使用条形图绘制一个月的每日报告?
【发布时间】:2012-04-10 09:06:01
【问题描述】:

我们使用 iReport 工具来创建 jrxml

假设,我们有一个包含每天信息的数据库表(日期为一列)

如果我们在 4 月 10 日(4 月)生成 4 月的每日报告。

我们确实看到生成了我的条形图(xaxis->day,y-axis->valuedata),但 x 轴范围仅显示从 1 到 10。

但我们希望看到从 1 到 30 的 x 轴范围,并且只绘制前 10 天的条形图。

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

欢迎任何帮助使用 iReport 实现这一目标。

谢谢, 森希尔VS

【问题讨论】:

    标签: jasper-reports ireport


    【解决方案1】:

    您需要为此创建图表定制器,并将图表定制器类分配给您的 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 一无所知。
    猜你喜欢
    • 2021-07-07
    • 1970-01-01
    • 2019-12-26
    • 1970-01-01
    • 1970-01-01
    • 2013-02-24
    • 1970-01-01
    • 2019-08-15
    • 2022-12-11
    相关资源
    最近更新 更多