2014年6月10日 星期二

[ Java 代碼範本 ] JFreeChart : Gantt Chart - XYTaskData set (1)

來源自 這裡 
UI 效果: (jfreechart-1.0.14) 
 

範例代碼: 
- XYTaskDatasetDemo1.java 
  1. package charts.gantt;  
  2.   
  3. import java.awt.Color;  
  4. import java.awt.Dimension;  
  5. import java.util.Date;  
  6.   
  7. import javax.swing.JPanel;  
  8.   
  9. import org.jfree.chart.ChartFactory;  
  10. import org.jfree.chart.ChartPanel;  
  11. import org.jfree.chart.ChartUtilities;  
  12. import org.jfree.chart.JFreeChart;  
  13. import org.jfree.chart.axis.DateAxis;  
  14. import org.jfree.chart.axis.SymbolAxis;  
  15. import org.jfree.chart.plot.PlotOrientation;  
  16. import org.jfree.chart.plot.XYPlot;  
  17. import org.jfree.chart.renderer.xy.XYBarRenderer;  
  18. import org.jfree.data.gantt.Task;  
  19. import org.jfree.data.gantt.TaskSeries;  
  20. import org.jfree.data.gantt.TaskSeriesCollection;  
  21. import org.jfree.data.gantt.XYTaskDataset;  
  22. import org.jfree.data.time.Day;  
  23. import org.jfree.data.time.Hour;  
  24. import org.jfree.data.time.RegularTimePeriod;  
  25. import org.jfree.data.time.TimeSeries;  
  26. import org.jfree.data.time.TimeSeriesDataItem;  
  27. import org.jfree.data.time.Year;  
  28. import org.jfree.data.xy.IntervalXYDataset;  
  29. import org.jfree.ui.ApplicationFrame;  
  30. import org.jfree.ui.RefineryUtilities;  
  31.   
  32. public class XYTaskDatasetDemo1 extends ApplicationFrame {  
  33.     public XYTaskDatasetDemo1(String paramString) {  
  34.         super(paramString);  
  35.         JPanel localJPanel = createDemoPanel();  
  36.         localJPanel.setPreferredSize(new Dimension(500300));  
  37.         setContentPane(localJPanel);  
  38.     }  
  39.   
  40.     private static JFreeChart createChart(  
  41.             IntervalXYDataset paramIntervalXYDataset) {  
  42.         JFreeChart localJFreeChart = ChartFactory.createXYBarChart(  
  43.                 "XYTaskDatasetDemo1""Resource"false"Timing",  
  44.                 paramIntervalXYDataset, PlotOrientation.HORIZONTAL, true,  
  45.                 falsefalse);  
  46.         localJFreeChart.setBackgroundPaint(Color.white);  
  47.         XYPlot localXYPlot = (XYPlot) localJFreeChart.getPlot();  
  48.         SymbolAxis localSymbolAxis = new SymbolAxis("Series"new String[] {  
  49.                 "Team A""Team B""Team C""Team D" });  
  50.         localSymbolAxis.setGridBandsVisible(false);  
  51.         localXYPlot.setDomainAxis(localSymbolAxis);  
  52.         XYBarRenderer localXYBarRenderer = (XYBarRenderer) localXYPlot  
  53.                 .getRenderer();  
  54.         localXYBarRenderer.setUseYInterval(true);  
  55.         localXYPlot.setRangeAxis(new DateAxis("Timing"));  
  56.         ChartUtilities.applyCurrentTheme(localJFreeChart);  
  57.         return localJFreeChart;  
  58.     }  
  59.   
  60.     public static JPanel createDemoPanel() {  
  61.         return new ChartPanel(createChart(createDataset()));  
  62.     }  
  63.   
  64.     private static IntervalXYDataset createDataset() {  
  65.         return new XYTaskDataset(createTasks());  
  66.     }  
  67.   
  68.     private static TaskSeriesCollection createTasks() {  
  69.         TimeSeries timeseries = new TimeSeries("L&G European Index Trust");  
  70.         RegularTimePeriod rtp = new Year(new Date());  
  71.         timeseries.add(new TimeSeriesDataItem(rtp, WIDTH));  
  72.   
  73.         TaskSeriesCollection localTaskSeriesCollection = new TaskSeriesCollection();  
  74.         TaskSeries localTaskSeries1 = new TaskSeries("Team A");  
  75.         localTaskSeries1.add(new Task("T1a"new Hour(11new Day())));  
  76.         localTaskSeries1.add(new Task("T1b"new Hour(14new Day())));  
  77.         localTaskSeries1.add(new Task("T1c"new Hour(16new Day())));  
  78.         TaskSeries localTaskSeries2 = new TaskSeries("Team B");  
  79.         localTaskSeries2.add(new Task("T2a"new Hour(13new Day())));  
  80.         localTaskSeries2.add(new Task("T2b"new Hour(19new Day())));  
  81.         localTaskSeries2.add(new Task("T2c"new Hour(21new Day())));  
  82.         TaskSeries localTaskSeries3 = new TaskSeries("Team C");  
  83.         localTaskSeries3.add(new Task("T3a"new Hour(13new Day())));  
  84.         localTaskSeries3.add(new Task("T3b"new Hour(19new Day())));  
  85.         localTaskSeries3.add(new Task("T3c"new Hour(21new Day())));  
  86.         TaskSeries localTaskSeries4 = new TaskSeries("Team D");  
  87.         localTaskSeries4.add(new Task("T4a"new Day()));  
  88.         localTaskSeriesCollection.add(localTaskSeries1);  
  89.         localTaskSeriesCollection.add(localTaskSeries2);  
  90.         localTaskSeriesCollection.add(localTaskSeries3);  
  91.         localTaskSeriesCollection.add(localTaskSeries4);  
  92.         return localTaskSeriesCollection;  
  93.     }  
  94.   
  95.     public static void main(String[] paramArrayOfString) {  
  96.         XYTaskDatasetDemo1 localXYTaskDatasetDemo1 = new XYTaskDatasetDemo1(  
  97.                 "JFreeChart : XYTaskDatasetDemo1.java");  
  98.         localXYTaskDatasetDemo1.pack();  
  99.         RefineryUtilities.centerFrameOnScreen(localXYTaskDatasetDemo1);  
  100.         localXYTaskDatasetDemo1.setVisible(true);  
  101.     }  
  102. }  

沒有留言:

張貼留言

[Git 常見問題] error: The following untracked working tree files would be overwritten by merge

  Source From  Here 方案1: // x -----删除忽略文件已经对 git 来说不识别的文件 // d -----删除未被添加到 git 的路径中的文件 // f -----强制运行 #   git clean -d -fx 方案2: 今天在服务器上  gi...