今回は CategoryDataset のサブタイプである IntervalCategoryDataset とそれを要求するチャート GanttChart を見ていきます。
Gantt Chart とはプロジェクト管理や生産管理などで用いられる表だそうです(wikipedia:ガントチャート)。 「Gantt」はこの表を発明した人の名前です。 Gant (= Groovy + Ant) とは関係ありません :-)
IntervalCategoryDataset インスタンスの取得方法
IntervalCategoryDataset の実装クラスには
- DefaultIntervalCategoryDataset
- SlidingGanttCategoryDataset
- TaskSeriesCollection
がありますが、ここでは DefaultIntervalCategoryDataset のみを見ていきます。
String[] series = ['Unresolved Period'] String[] categories = [ 'Continuum Hypothesis', 'Four color theorem', 'Fermat\'s Last Theorem', 'Kepler conjecture', 'Poincare Conjecture'] int m = series.size(), n = categories.size() def dataset = new DefaultIntervalCategoryDataset(series, categories, new Number[m][n], new Number[m][n]) dataset.setStartValue(0, 'Continuum Hypothesis', year(1877)) dataset.setEndValue(0, 'Continuum Hypothesis', year(1963)) dataset.setStartValue(0, 'Four color theorem', year(1852)) dataset.setEndValue(0, 'Four color theorem', year(1976)) dataset.setStartValue(0, 'Kepler conjecture', year(1611)) dataset.setEndValue(0, 'Kepler conjecture', year(1998)) dataset.setStartValue(0, 'Fermat\'s Last Theorem', year(1637)) dataset.setEndValue(0, 'Fermat\'s Last Theorem', year(1995)) dataset.setStartValue(0, 'Poincare Conjecture', year(1904)) dataset.setEndValue(0, 'Poincare Conjecture', year(2003)) def long year(int year){ def date = Date.parse('yyyy', year.toString()) return date.time }
- 分類のためのキーとして「シリーズ」と「カテゴリー」があります。 どちらも Comparable の配列を要求していますが、文字列やインデックスを指定すれば良いでしょう。
- データの値としては「開始」と「終了」を表す2つの数値が求められますが、Gant Chart ではこれらは時刻もしくは日程を表す値になります。 時刻や日程を表す Date オブジェクトを生成して、getTime() メソッド(もしくは time プロパティ)で long 値を取得し、それをセットすると良いかと思います。
GanttChart
ChartFactory.createGanttChart('Gantt Chart', 'Mathematical Problem', 'Year', dataset, true, true, true)