0

jrxmlの作成にはiReportツールを使用します

毎日の情報を含むdbテーブルがあると仮定します(日付を1つの列として)

4 月 10 日 (4 月の) 月 4 月の日報の生成に行くとします。

棒グラフ (xaxis->day,y-axis->valuedata) が生成されているのがわかりますが、x 軸の範囲は 1 から 10 までしか表示されません。

ただし、x 軸の範囲を 1 から 30 日まで、棒グラフを最初の 10 日間のみ表示したいと考えています。

上記の理由は、この x 軸の日付フィールドをマップしたためです (そして、データベースには 10 日までのデータしかありません)。しかし、このireportツールに関する私の知識から、これを達成する方法がわかりません

iReport を使用してこれを達成するための助けを歓迎します。

ありがとう、センティルVS

4

1 に答える 1

1

そのためのチャート カスタマイザーを作成し、Chart カスタマイザー クラスを 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) {
                // 
            }
        }
    }

}

よろしく

ジュリオ

于 2012-04-24T08:47:55.153 に答える