- Home ›
- JFreeChartを使ったグラフ作成 ›
- ガントチャート(GanttChart) ›
- HERE
ガントチャートの作成(createGanttChartメソッド)
ガントチャートの基本的な作成方法を確認します。
まずChartFactoryクラスの「createGanttChart」メソッドを使ってガントチャートを扱うJFreeChartクラスのオブジェクトを作成します。
createGanttChart public static JFreeChart createGanttChart(java.lang.String title, java.lang.String categoryAxisLabel, java.lang.String dateAxisLabel, IntervalCategoryDataset dataset, boolean legend, boolean tooltips, boolean urls)
Creates a Gantt chart using the supplied attributes plus default values where required. The chart object returned by this method uses a CategoryPlot instance as the plot, with a CategoryAxis for the domain axis, a DateAxis as the range axis, and a GanttRenderer as the renderer. Parameters: title - the chart title (null permitted). categoryAxisLabel - the label for the category axis (null permitted). dateAxisLabel - the label for the date axis (null permitted). dataset - the dataset for the chart (null permitted). legend - a flag specifying whether or not a legend is required. tooltips - configure chart to generate tool tips? urls - configure chart to generate URLs? Returns: A Gantt chart.
1番目の引数にグラフのタイトルを文字列で指定します。
2番目の引数には項目を表す軸のラベルを文字列で指定します。Y軸に設定されます。3番目の引数には日付を表す軸のラベルを文字列で指定します。X軸(上部)に設定されます。
4番目の引数にはグラフのデータをIntervalCategoryDatasetインターフェースを実装したクラスのオブジェクトで指定します。今回はTaskSeriesCollectionクラスを使います。詳細は次のページで確認します。
5番目の引数には凡例を表示するかどうかを「true」か「false」で指定します。
6番目の引数にはツールチップを作成するかどうかを「true」か「false」で指定します。
7番目の引数にはURLを作成するかどうかを「true」か「false」で指定します。
実際の使い方は次のようになります。
TaskSeriesCollection data = new TaskSeriesCollection(); JFreeChart chart = ChartFactory.createGanttChart("プロジェクト管理", "項目", "日程", data, true, false, false);
実際のデータの追加方法は次のページで確認します。
サンプルプログラム
では簡単なサンプルを作成して試してみます。
import org.jfree.chart.JFreeChart; import org.jfree.chart.ChartFactory; import org.jfree.data.gantt.TaskSeriesCollection; import javax.swing.JFrame; import java.awt.BorderLayout; import org.jfree.chart.ChartPanel; public class Test1_1 extends JFrame{ public static void main(String[] args) { Test1_1 frame = new Test1_1(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setBounds(10, 10, 500, 500); frame.setTitle("グラフサンプル"); frame.setVisible(true); } Test1_1(){ TaskSeriesCollection data = new TaskSeriesCollection(); JFreeChart chart = ChartFactory.createGanttChart("プロジェクト管理", "項目", "日程", data, true, false, false); ChartPanel cpanel = new ChartPanel(chart); getContentPane().add(cpanel, BorderLayout.CENTER); } }
上記をコンパイルした後で実行すると次のようにJavaアプリケーションが起動します。
( Written by Tatsuo Ikura )