2015年11月10日 星期二

[ Java 代碼範本 ] JFreeChart : showcases - XYTaskDatasetDemo2

Source From Here
UI 效果: (jfreechart-1.0.14)

範例代碼:
- XYTaskDatasetDemo2.groovy
  1. package showcases  
  2.   
  3. import java.awt.Color;  
  4. import java.awt.Dimension;  
  5. import java.awt.geom.Ellipse2D;  
  6. import javax.swing.JPanel;  
  7. import org.jfree.chart.ChartPanel;  
  8. import org.jfree.chart.ChartUtilities;  
  9. import org.jfree.chart.JFreeChart;  
  10. import org.jfree.chart.axis.DateAxis;  
  11. import org.jfree.chart.axis.NumberAxis;  
  12. import org.jfree.chart.axis.SymbolAxis;  
  13. import org.jfree.chart.plot.CombinedDomainXYPlot;  
  14. import org.jfree.chart.plot.XYPlot;  
  15. import org.jfree.chart.renderer.xy.XYBarRenderer;  
  16. import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;  
  17. import org.jfree.data.gantt.Task;  
  18. import org.jfree.data.gantt.TaskSeries;  
  19. import org.jfree.data.gantt.TaskSeriesCollection;  
  20. import org.jfree.data.gantt.XYTaskDataset;  
  21. import org.jfree.data.time.Day;  
  22. import org.jfree.data.time.Hour;  
  23. import org.jfree.data.time.TimeSeries;  
  24. import org.jfree.data.time.TimeSeriesCollection;  
  25. import org.jfree.data.xy.IntervalXYDataset;  
  26. import org.jfree.data.xy.XYDataset;  
  27. import org.jfree.ui.ApplicationFrame;  
  28. import org.jfree.ui.RefineryUtilities;  
  29.   
  30. class XYTaskDatasetDemo2 extends ApplicationFrame{  
  31.     public XYTaskDatasetDemo2(String paramString)  
  32.     {  
  33.       super(paramString);  
  34.       JPanel localJPanel = createDemoPanel();  
  35.       localJPanel.setPreferredSize(new Dimension(800500));  
  36.       setContentPane(localJPanel);  
  37.     }  
  38.     
  39.     private static XYPlot createSubplot1(XYDataset paramXYDataset)  
  40.     {  
  41.       XYLineAndShapeRenderer localXYLineAndShapeRenderer = new XYLineAndShapeRenderer();  
  42.       localXYLineAndShapeRenderer.setUseFillPaint(true);  
  43.       localXYLineAndShapeRenderer.setBaseFillPaint(Color.white);  
  44.       localXYLineAndShapeRenderer.setBaseShape(new Ellipse2D.Double(-4.0D, -4.0D, 8.0D, 8.0D));  
  45.       localXYLineAndShapeRenderer.setAutoPopulateSeriesShape(false);  
  46.       NumberAxis localNumberAxis = new NumberAxis("Y");  
  47.       localNumberAxis.setLowerMargin(0.1D);  
  48.       localNumberAxis.setUpperMargin(0.1D);  
  49.       XYPlot localXYPlot = new XYPlot(paramXYDataset, new DateAxis("Time"), localNumberAxis, localXYLineAndShapeRenderer);  
  50.       return localXYPlot;  
  51.     }  
  52.     
  53.     private static XYPlot createSubplot2(IntervalXYDataset paramIntervalXYDataset)  
  54.     {  
  55.       DateAxis localDateAxis = new DateAxis("Date/Time");  
  56.       def teamNames = [ "Team A""Team B""Team C""Team D""Team E" ] as String[]  
  57.       SymbolAxis localSymbolAxis = new SymbolAxis("Resources", teamNames);  
  58.       localSymbolAxis.setGridBandsVisible(false);  
  59.       XYBarRenderer localXYBarRenderer = new XYBarRenderer();  
  60.       localXYBarRenderer.setUseYInterval(true);  
  61.       XYPlot localXYPlot = new XYPlot(paramIntervalXYDataset, localDateAxis, localSymbolAxis, localXYBarRenderer);  
  62.       return localXYPlot;  
  63.     }  
  64.     
  65.     private static JFreeChart createChart()  
  66.     {  
  67.       CombinedDomainXYPlot localCombinedDomainXYPlot = new CombinedDomainXYPlot(new DateAxis("Date/Time"));  
  68.       localCombinedDomainXYPlot.add(createSubplot1(createDataset1()));  
  69.       localCombinedDomainXYPlot.add(createSubplot2(createDataset2()));  
  70.       JFreeChart localJFreeChart = new JFreeChart("XYTaskDatasetDemo2", localCombinedDomainXYPlot);  
  71.       localJFreeChart.setBackgroundPaint(Color.white);  
  72.       ChartUtilities.applyCurrentTheme(localJFreeChart);  
  73.       return localJFreeChart;  
  74.     }  
  75.     
  76.     public static JPanel createDemoPanel()  
  77.     {  
  78.       return new ChartPanel(createChart());  
  79.     }  
  80.     
  81.     private static XYDataset createDataset1()  
  82.     {  
  83.       TimeSeriesCollection localTimeSeriesCollection = new TimeSeriesCollection();  
  84.       TimeSeries localTimeSeries = new TimeSeries("Time Series 1", Hour.class);  
  85.       localTimeSeries.add(new Hour(0new Day()), 20214.5D);  
  86.       localTimeSeries.add(new Hour(4new Day()), 73346.5D);  
  87.       localTimeSeries.add(new Hour(8new Day()), 54643.599999999999D);  
  88.       localTimeSeries.add(new Hour(12new Day()), 92683.800000000003D);  
  89.       localTimeSeries.add(new Hour(16new Day()), 110235.39999999999D);  
  90.       localTimeSeries.add(new Hour(20new Day()), 120742.5D);  
  91.       localTimeSeries.add(new Hour(24new Day()), 90654.5D);  
  92.       localTimeSeriesCollection.addSeries(localTimeSeries);  
  93.       return localTimeSeriesCollection;  
  94.     }  
  95.     
  96.     private static IntervalXYDataset createDataset2()  
  97.     {  
  98.       XYTaskDataset localXYTaskDataset = new XYTaskDataset(createTasks());  
  99.       localXYTaskDataset.setTransposed(true);  
  100.       localXYTaskDataset.setSeriesWidth(0.6D);  
  101.       return localXYTaskDataset;  
  102.     }  
  103.     
  104.     private static TaskSeriesCollection createTasks()  
  105.     {  
  106.       TaskSeriesCollection localTaskSeriesCollection = new TaskSeriesCollection();  
  107.       TaskSeries localTaskSeries1 = new TaskSeries("Team A");  
  108.       localTaskSeries1.add(new Task("T1a"new Hour(11new Day())));  
  109.       localTaskSeries1.add(new Task("T1b"new Hour(14new Day())));  
  110.       localTaskSeries1.add(new Task("T1c"new Hour(16new Day())));  
  111.       TaskSeries localTaskSeries2 = new TaskSeries("Team B");  
  112.       localTaskSeries2.add(new Task("T2a"new Hour(13new Day())));  
  113.       localTaskSeries2.add(new Task("T2b"new Hour(19new Day())));  
  114.       localTaskSeries2.add(new Task("T2c"new Hour(21new Day())));  
  115.       TaskSeries localTaskSeries3 = new TaskSeries("Team C");  
  116.       localTaskSeries3.add(new Task("T3a"new Hour(13new Day())));  
  117.       localTaskSeries3.add(new Task("T3b"new Hour(19new Day())));  
  118.       localTaskSeries3.add(new Task("T3c"new Hour(21new Day())));  
  119.       TaskSeries localTaskSeries4 = new TaskSeries("Team D");  
  120.       localTaskSeries4.add(new Task("T4a"new Day()));  
  121.       TaskSeries localTaskSeries5 = new TaskSeries("Team E");  
  122.       localTaskSeries5.add(new Task("T5a"new Day()));  
  123.       localTaskSeriesCollection.add(localTaskSeries1);  
  124.       localTaskSeriesCollection.add(localTaskSeries2);  
  125.       localTaskSeriesCollection.add(localTaskSeries3);  
  126.       localTaskSeriesCollection.add(localTaskSeries4);  
  127.       localTaskSeriesCollection.add(localTaskSeries5);  
  128.       return localTaskSeriesCollection;  
  129.     }  
  130.     
  131.     public static void main(String[] paramArrayOfString)  
  132.     {  
  133.       XYTaskDatasetDemo2 localXYTaskDatasetDemo2 = new XYTaskDatasetDemo2("JFreeChart : XYTaskDatasetDemo2.java");  
  134.       localXYTaskDatasetDemo2.pack();  
  135.       RefineryUtilities.centerFrameOnScreen(localXYTaskDatasetDemo2);  
  136.       localXYTaskDatasetDemo2.setVisible(true);  
  137.     }  
  138. }  

沒有留言:

張貼留言

[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...