1 40 41 package org.jfree.chart.demo; 42 43 import java.util.Calendar ; 44 import java.util.Date ; 45 46 import org.jfree.chart.ChartFactory; 47 import org.jfree.chart.ChartPanel; 48 import org.jfree.chart.JFreeChart; 49 import org.jfree.data.IntervalCategoryDataset; 50 import org.jfree.data.gantt.Task; 51 import org.jfree.data.gantt.TaskSeries; 52 import org.jfree.data.gantt.TaskSeriesCollection; 53 import org.jfree.data.time.SimpleTimePeriod; 54 import org.jfree.ui.ApplicationFrame; 55 import org.jfree.ui.RefineryUtilities; 56 57 66 public class GanttDemo1 extends ApplicationFrame { 67 68 73 public GanttDemo1(String title) { 74 75 super(title); 76 77 IntervalCategoryDataset dataset = createDataset(); 78 JFreeChart chart = createChart(dataset); 79 80 ChartPanel chartPanel = new ChartPanel(chart); 82 chartPanel.setPreferredSize(new java.awt.Dimension (500, 270)); 83 setContentPane(chartPanel); 84 85 } 86 87 98 103 public static IntervalCategoryDataset createDataset() { 104 105 TaskSeries s1 = new TaskSeries("Scheduled"); 106 s1.add(new Task("Write Proposal", 107 new SimpleTimePeriod(date(1, Calendar.APRIL, 2001), 108 date(5, Calendar.APRIL, 2001)))); 109 s1.add(new Task("Obtain Approval", 110 new SimpleTimePeriod(date(9, Calendar.APRIL, 2001), 111 date(9, Calendar.APRIL, 2001)))); 112 s1.add(new Task("Requirements Analysis", 113 new SimpleTimePeriod(date(10, Calendar.APRIL, 2001), 114 date(5, Calendar.MAY, 2001)))); 115 s1.add(new Task("Design Phase", 116 new SimpleTimePeriod(date(6, Calendar.MAY, 2001), 117 date(30, Calendar.MAY, 2001)))); 118 s1.add(new Task("Design Signoff", 119 new SimpleTimePeriod(date(2, Calendar.JUNE, 2001), 120 date(2, Calendar.JUNE, 2001)))); 121 s1.add(new Task("Alpha Implementation", 122 new SimpleTimePeriod(date(3, Calendar.JUNE, 2001), 123 date(31, Calendar.JULY, 2001)))); 124 s1.add(new Task("Design Review", 125 new SimpleTimePeriod(date(1, Calendar.AUGUST, 2001), 126 date(8, Calendar.AUGUST, 2001)))); 127 s1.add(new Task("Revised Design Signoff", 128 new SimpleTimePeriod(date(10, Calendar.AUGUST, 2001), 129 date(10, Calendar.AUGUST, 2001)))); 130 s1.add(new Task("Beta Implementation", 131 new SimpleTimePeriod(date(12, Calendar.AUGUST, 2001), 132 date(12, Calendar.SEPTEMBER, 2001)))); 133 s1.add(new Task("Testing", 134 new SimpleTimePeriod(date(13, Calendar.SEPTEMBER, 2001), 135 date(31, Calendar.OCTOBER, 2001)))); 136 s1.add(new Task("Final Implementation", 137 new SimpleTimePeriod(date(1, Calendar.NOVEMBER, 2001), 138 date(15, Calendar.NOVEMBER, 2001)))); 139 s1.add(new Task("Signoff", 140 new SimpleTimePeriod(date(28, Calendar.NOVEMBER, 2001), 141 date(30, Calendar.NOVEMBER, 2001)))); 142 143 TaskSeries s2 = new TaskSeries("Actual"); 144 s2.add(new Task("Write Proposal", 145 new SimpleTimePeriod(date(1, Calendar.APRIL, 2001), 146 date(5, Calendar.APRIL, 2001)))); 147 s2.add(new Task("Obtain Approval", 148 new SimpleTimePeriod(date(9, Calendar.APRIL, 2001), 149 date(9, Calendar.APRIL, 2001)))); 150 s2.add(new Task("Requirements Analysis", 151 new SimpleTimePeriod(date(10, Calendar.APRIL, 2001), 152 date(15, Calendar.MAY, 2001)))); 153 s2.add(new Task("Design Phase", 154 new SimpleTimePeriod(date(15, Calendar.MAY, 2001), 155 date(17, Calendar.JUNE, 2001)))); 156 s2.add(new Task("Design Signoff", 157 new SimpleTimePeriod(date(30, Calendar.JUNE, 2001), 158 date(30, Calendar.JUNE, 2001)))); 159 s2.add(new Task("Alpha Implementation", 160 new SimpleTimePeriod(date(1, Calendar.JULY, 2001), 161 date(12, Calendar.SEPTEMBER, 2001)))); 162 s2.add(new Task("Design Review", 163 new SimpleTimePeriod(date(12, Calendar.SEPTEMBER, 2001), 164 date(22, Calendar.SEPTEMBER, 2001)))); 165 s2.add(new Task("Revised Design Signoff", 166 new SimpleTimePeriod(date(25, Calendar.SEPTEMBER, 2001), 167 date(27, Calendar.SEPTEMBER, 2001)))); 168 s2.add(new Task("Beta Implementation", 169 new SimpleTimePeriod(date(27, Calendar.SEPTEMBER, 2001), 170 date(30, Calendar.OCTOBER, 2001)))); 171 s2.add(new Task("Testing", 172 new SimpleTimePeriod(date(31, Calendar.OCTOBER, 2001), 173 date(17, Calendar.NOVEMBER, 2001)))); 174 s2.add(new Task("Final Implementation", 175 new SimpleTimePeriod(date(18, Calendar.NOVEMBER, 2001), 176 date(5, Calendar.DECEMBER, 2001)))); 177 s2.add(new Task("Signoff", 178 new SimpleTimePeriod(date(10, Calendar.DECEMBER, 2001), 179 date(11, Calendar.DECEMBER, 2001)))); 180 181 TaskSeriesCollection collection = new TaskSeriesCollection(); 182 collection.add(s1); 183 collection.add(s2); 184 185 return collection; 186 } 187 188 197 private static Date date(int day, int month, int year) { 198 199 Calendar calendar = Calendar.getInstance(); 200 calendar.set(year, month, day); 201 Date result = calendar.getTime(); 202 return result; 203 204 } 205 206 213 private JFreeChart createChart(IntervalCategoryDataset dataset) { 214 JFreeChart chart = ChartFactory.createGanttChart( 215 "Gantt Chart Demo", "Task", "Date", dataset, true, true, false ); 223 return chart; 224 } 225 226 231 public static void main(String [] args) { 232 233 GanttDemo1 demo = new GanttDemo1("Gantt Chart Demo 1"); 234 demo.pack(); 235 RefineryUtilities.centerFrameOnScreen(demo); 236 demo.setVisible(true); 237 238 } 239 240 } 241 | Popular Tags |