1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
|
public class SwingExempleGantt extends ApplicationFrame{
public SwingExempleGantt(String title)
{
super(title);
JFrame frame = new JFrame("Hello World!");
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
JPanel panel;
panel = new JPanel(new BorderLayout());
IntervalCategoryDataset dataset = createDataset();
final JFreeChart chart = ChartFactory.createGanttChart(
"Diagramme de Gantt", // chart title
"Machines", // domain axis label
"Durée", // range axis label
dataset, // data
true, // include legend
true, // tooltips
false // urls
);
final CategoryPlot plot = (CategoryPlot) chart.getPlot();
// plot.getDomainAxis().setMaxCategoryLabelWidthRatio(10.0f);
final CategoryItemRenderer renderer = plot.getRenderer();
CategoryItemLabelGenerator generator = new StandardCategoryItemLabelGenerator("{2}", new DecimalFormat("0.00"));
renderer.setBaseItemLabelGenerator(generator);
plot.getRenderer().setSeriesPaint(0, new Color(128, 0, 0));
plot.getRenderer().setSeriesPaint(1, new Color(0, 0, 255));
renderer.setSeriesPaint(0, Color.blue);
renderer.setBaseItemLabelsVisible(true);
// Imposer que les étiquettes des graduations de l'axe des ordonnées soient des entiers
// add the chart to a panel...
ChartPanel chartPanel = new ChartPanel(chart,
true, //propreties
true, //save
true, //print
true, //zoom
true); //tooltips
chartPanel.setPreferredSize(new java.awt.Dimension(400, 270));
setContentPane(chartPanel);
setContentPane(panel);
setSize(600, 350);
panel.add(chartPanel);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
/**
* Creates a sample dataset for a Gantt chart.
*
* @return The dataset.
*/
public static IntervalCategoryDataset createDataset() {
TaskSeries s1 = new TaskSeries("Scheduled");
// Machine1
final Task M1 = new Task("Machine M1",
new SimpleTimePeriod( new Integer(2), new Integer(15)));
//sous tache1
final Task O1 = new Task("O1",
new SimpleTimePeriod( new Date(2), new Date(7)));
O1.setPercentComplete(1.0);
// sous tache2
final Task O2 = new Task("O2",
new SimpleTimePeriod( new Date(10), new Date(15)));
O2.setPercentComplete(1.0);
//ajout des sous taches
M1.addSubtask(O1);
M1.addSubtask(O2);
s1.add(M1);
// Machine2
final Task M2 = new Task("Machine M2",
new SimpleTimePeriod( new Date(0), new Date(10)));
//sous tache21: operation O3
final Task O3 = new Task("O3",
new SimpleTimePeriod( new Date(0), new Date(7)));
O3.setPercentComplete(1.0);
// sous tache22: opereration O4
final Task O4 = new Task("O4",
new SimpleTimePeriod( new Date(5), new Date(10)));
O4.setPercentComplete(1.0);
//ajout des sous taches
M2.addSubtask(O3);
M2.addSubtask(O4);
s1.add(M2);
TaskSeriesCollection collection = new TaskSeriesCollection();
collection.add(s1);
return collection;
}
/**
* Utility method for creating <code>Date</code> objects.
*
* @param day the date.
* @param month the month.
* @param year the year.
*
* @return a date.
*/
private static Date date(int day, int month, int year) {
Calendar calendar = Calendar.getInstance();
calendar.set(year, month, day);
Date result = calendar.getTime();
return result;
}
/**
* Creates a chart.
*
* @param dataset the dataset.
*
* @return The chart.
*/
private JFreeChart createChart(IntervalCategoryDataset dataset) {
JFreeChart chart = ChartFactory.createGanttChart(
"Gantt Chart Demo", // chart title
"Task", // domain axis label : domaine des ordonnées Tache Num
"Date", // range axis label : domaine des abcsisses
dataset, // data
true, // include legend
true, // tooltips
false // urls
);
chart.getCategoryPlot().getDomainAxis().setMaximumCategoryLabelWidthRatio(10.0f);
return chart;
}
} |
Partager