2016年1月10日 星期日

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

Source From Here
UI Effect
 


Sample Code
  1. package report.demo;  
  2.   
  3. import java.awt.*;     
  4. import java.text.DecimalFormat;     
  5. import java.text.SimpleDateFormat;     
  6. import javax.swing.JPanel;     
  7. import org.jfree.chart.ChartPanel;     
  8. import org.jfree.chart.JFreeChart;     
  9. import org.jfree.chart.axis.*;     
  10. import org.jfree.chart.block.BlockBorder;     
  11. import org.jfree.chart.labels.*;     
  12. import org.jfree.chart.plot.XYPlot;     
  13. import org.jfree.chart.renderer.xy.StackedXYBarRenderer;     
  14. import org.jfree.chart.title.LegendTitle;     
  15. import org.jfree.chart.title.TextTitle;     
  16. import org.jfree.data.time.TimeTableXYDataset;     
  17. import org.jfree.data.time.Year;     
  18. import org.jfree.data.xy.TableXYDataset;     
  19. import org.jfree.ui.*;   
  20.   
  21.   
  22. public class StackedXYBarChartDemo2 extends ApplicationFrame{  
  23.     public StackedXYBarChartDemo2(String s)     
  24.     {     
  25.         super(s);     
  26.         JPanel jpanel = createDemoPanel();     
  27.         jpanel.setPreferredSize(new Dimension(750500));     
  28.         setContentPane(jpanel);     
  29.     }     
  30.      
  31.     private static TableXYDataset createDataset()     
  32.     {     
  33.         TimeTableXYDataset timetablexydataset = new TimeTableXYDataset();     
  34.         timetablexydataset.add(new Year(1983), 0.0D, "Albatrosses");     
  35.         timetablexydataset.add(new Year(1984), 2D, "Albatrosses");     
  36.         timetablexydataset.add(new Year(1985), 1.0D, "Albatrosses");     
  37.         timetablexydataset.add(new Year(1986), 1.0D, "Albatrosses");     
  38.         timetablexydataset.add(new Year(1987), 2D, "Albatrosses");     
  39.         timetablexydataset.add(new Year(1988), 2D, "Albatrosses");     
  40.         timetablexydataset.add(new Year(1989), 1.0D, "Albatrosses");     
  41.         timetablexydataset.add(new Year(1990), 5D, "Albatrosses");     
  42.         timetablexydataset.add(new Year(1991), 5D, "Albatrosses");     
  43.         timetablexydataset.add(new Year(1992), 2D, "Albatrosses");     
  44.         timetablexydataset.add(new Year(1993), 4D, "Albatrosses");     
  45.         timetablexydataset.add(new Year(1994), 3D, "Albatrosses");     
  46.         timetablexydataset.add(new Year(1995), 2D, "Albatrosses");     
  47.         timetablexydataset.add(new Year(1996), 1.0D, "Albatrosses");     
  48.         timetablexydataset.add(new Year(1997), 2D, "Albatrosses");     
  49.         timetablexydataset.add(new Year(1998), 1.0D, "Albatrosses");     
  50.         timetablexydataset.add(new Year(1999), 4D, "Albatrosses");     
  51.         timetablexydataset.add(new Year(2000), 6D, "Albatrosses");     
  52.         timetablexydataset.add(new Year(2001), 5D, "Albatrosses");     
  53.         timetablexydataset.add(new Year(2002), 4D, "Albatrosses");     
  54.         timetablexydataset.add(new Year(2003), 2D, "Albatrosses");     
  55.         timetablexydataset.add(new Year(1983), 21D, "Aces");     
  56.         timetablexydataset.add(new Year(1984), 24D, "Aces");     
  57.         timetablexydataset.add(new Year(1985), 32D, "Aces");     
  58.         timetablexydataset.add(new Year(1986), 20D, "Aces");     
  59.         timetablexydataset.add(new Year(1987), 28D, "Aces");     
  60.         timetablexydataset.add(new Year(1988), 17D, "Aces");     
  61.         timetablexydataset.add(new Year(1989), 31D, "Aces");     
  62.         timetablexydataset.add(new Year(1990), 32D, "Aces");     
  63.         timetablexydataset.add(new Year(1991), 29D, "Aces");     
  64.         timetablexydataset.add(new Year(1992), 31D, "Aces");     
  65.         timetablexydataset.add(new Year(1993), 25D, "Aces");     
  66.         timetablexydataset.add(new Year(1994), 44D, "Aces");     
  67.         timetablexydataset.add(new Year(1995), 35D, "Aces");     
  68.         timetablexydataset.add(new Year(1996), 40D, "Aces");     
  69.         timetablexydataset.add(new Year(1997), 32D, "Aces");     
  70.         timetablexydataset.add(new Year(1998), 32D, "Aces");     
  71.         timetablexydataset.add(new Year(1999), 30D, "Aces");     
  72.         timetablexydataset.add(new Year(2000), 29D, "Aces");     
  73.         timetablexydataset.add(new Year(2001), 28D, "Aces");     
  74.         timetablexydataset.add(new Year(2002), 39D, "Aces");     
  75.         timetablexydataset.add(new Year(2003), 32D, "Aces");     
  76.         return timetablexydataset;     
  77.     }     
  78.      
  79.     private static JFreeChart createChart(TableXYDataset tablexydataset)     
  80.     {     
  81.         DateAxis dateaxis = new DateAxis("Date");     
  82.         dateaxis.setTickMarkPosition(DateTickMarkPosition.MIDDLE);     
  83.         dateaxis.setLowerMargin(0.01D);     
  84.         dateaxis.setUpperMargin(0.01D);     
  85.         NumberAxis numberaxis = new NumberAxis("Count");     
  86.         numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());     
  87.         numberaxis.setUpperMargin(0.10000000000000001D);     
  88.         StackedXYBarRenderer stackedxybarrenderer = new StackedXYBarRenderer(0.14999999999999999D);     
  89.         stackedxybarrenderer.setDrawBarOutline(false);     
  90.         stackedxybarrenderer.setBaseItemLabelsVisible(true);     
  91.         stackedxybarrenderer.setBaseItemLabelGenerator(new StandardXYItemLabelGenerator());     
  92.         stackedxybarrenderer.setBasePositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BOTTOM_CENTER));     
  93.         stackedxybarrenderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator("{0} : {1} = {2}"new SimpleDateFormat("yyyy"), new DecimalFormat("0")));     
  94.         XYPlot xyplot = new XYPlot(tablexydataset, dateaxis, numberaxis, stackedxybarrenderer);     
  95.         JFreeChart jfreechart = new JFreeChart("Holes-In-One / Double Eagles", xyplot);     
  96.         jfreechart.removeLegend();     
  97.         jfreechart.addSubtitle(new TextTitle("PGA Tour, 1983 to 2003"));     
  98.         TextTitle texttitle = new TextTitle("http://www.golfdigest.com/majors/masters/index.ssf?/majors/masters/gw20040402albatross.html"new Font("Dialog"08));     
  99.         jfreechart.addSubtitle(texttitle);     
  100.         jfreechart.setTextAntiAlias(RenderingHints.VALUE_TEXT_ANTIALIAS_DEFAULT);     
  101.         LegendTitle legendtitle = new LegendTitle(xyplot);     
  102.         legendtitle.setBackgroundPaint(Color.white);     
  103.         legendtitle.setFrame(new BlockBorder());     
  104.         legendtitle.setPosition(RectangleEdge.BOTTOM);     
  105.         jfreechart.addSubtitle(legendtitle);     
  106.         return jfreechart;     
  107.     }     
  108.      
  109.     public static JPanel createDemoPanel()     
  110.     {     
  111.         JFreeChart jfreechart = createChart(createDataset());     
  112.         return new ChartPanel(jfreechart);     
  113.     }     
  114.      
  115.     public static void main(String args[])     
  116.     {     
  117.         StackedXYBarChartDemo2 stackedxybarchartdemo2 = new StackedXYBarChartDemo2("JFreeChart: Stacked XY Bar Chart Demo 2");     
  118.         stackedxybarchartdemo2.pack();     
  119.         RefineryUtilities.centerFrameOnScreen(stackedxybarchartdemo2);     
  120.         stackedxybarchartdemo2.setVisible(true);     
  121.     }  
  122. }  

1 則留言:

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