2015年12月2日 星期三

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

UI Effect


Sample Code
  1. package showcases;  
  2.   
  3. import org.jfree.chart.ChartFactory;  
  4. import org.jfree.chart.ChartPanel;  
  5. import org.jfree.chart.JFreeChart;  
  6. import org.jfree.chart.axis.NumberAxis;  
  7. import org.jfree.chart.labels.ItemLabelAnchor;  
  8. import org.jfree.chart.labels.ItemLabelPosition;  
  9. import org.jfree.chart.labels.StandardCategoryItemLabelGenerator;  
  10. import org.jfree.chart.plot.CategoryPlot;  
  11. import org.jfree.chart.plot.PlotOrientation;  
  12. import org.jfree.chart.renderer.category.StatisticalBarRenderer;  
  13. import org.jfree.data.category.CategoryDataset;  
  14. import org.jfree.data.statistics.DefaultStatisticalCategoryDataset;  
  15. import org.jfree.ui.ApplicationFrame;  
  16. import org.jfree.ui.RefineryUtilities;  
  17. import org.jfree.ui.TextAnchor;  
  18.   
  19. import javax.swing.*;  
  20. import java.awt.*;  
  21.   
  22. /** 
  23. * https://code.google.com/p/grape/source/browse/trunk/code/dealWithExcel/src/shai/jfreechart/StatisticalBarChartDemo1.java?r=50 
  24. * @author 奎慶 
  25. */  
  26. public class StatisticalBarChartDemo1 extends ApplicationFrame{  
  27.     public StatisticalBarChartDemo1(String paramString) {  
  28.         super(paramString);  
  29.         JPanel localJPanel = createDemoPanel();  
  30.         localJPanel.setPreferredSize(new Dimension(750500));  
  31.         setContentPane(localJPanel);  
  32.     }  
  33.   
  34.     private static CategoryDataset createDataset() {  
  35.         DefaultStatisticalCategoryDataset localDefaultStatisticalCategoryDataset = new DefaultStatisticalCategoryDataset();  
  36.         localDefaultStatisticalCategoryDataset.add(10.0D, 2.4D, "Row 1""Column 1");  
  37.         localDefaultStatisticalCategoryDataset.add(15.0D, 4.4D, "Row 1""Column 2");  
  38.         localDefaultStatisticalCategoryDataset.add(13.0D, 2.1D, "Row 1""Column 3");  
  39.         localDefaultStatisticalCategoryDataset.add(7.0D, 1.3D, "Row 1""Column 4");  
  40.         localDefaultStatisticalCategoryDataset.add(22.0D, 2.4D, "Row 2""Column 1");  
  41.         localDefaultStatisticalCategoryDataset.add(18.0D, 4.4D, "Row 2""Column 2");  
  42.         localDefaultStatisticalCategoryDataset.add(28.0D, 2.1D, "Row 2""Column 3");  
  43.         localDefaultStatisticalCategoryDataset.add(17.0D, 1.3D, "Row 2""Column 4");  
  44.         return localDefaultStatisticalCategoryDataset;  
  45.     }  
  46.   
  47.     private static JFreeChart createChart(CategoryDataset paramCategoryDataset) {  
  48.         JFreeChart localJFreeChart = ChartFactory.createLineChart("Statistical Bar Chart Demo 1""Type""Value", paramCategoryDataset, PlotOrientation.VERTICAL, truetruefalse);  
  49.         CategoryPlot localCategoryPlot = (CategoryPlot) localJFreeChart.getPlot();  
  50.         NumberAxis localNumberAxis = (NumberAxis) localCategoryPlot.getRangeAxis();  
  51.         localNumberAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());  
  52.         localNumberAxis.setAutoRangeIncludesZero(false);  
  53.         StatisticalBarRenderer localStatisticalBarRenderer = new StatisticalBarRenderer();  
  54.         localStatisticalBarRenderer.setDrawBarOutline(false);  
  55.         localStatisticalBarRenderer.setErrorIndicatorPaint(Color.black);  
  56.         localCategoryPlot.setRenderer(localStatisticalBarRenderer);  
  57.         localStatisticalBarRenderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());  
  58.         localStatisticalBarRenderer.setBaseItemLabelsVisible(true);  
  59.         localStatisticalBarRenderer.setBaseItemLabelPaint(Color.yellow);  
  60.         localStatisticalBarRenderer.setBasePositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.INSIDE6, TextAnchor.BOTTOM_CENTER));  
  61.         GradientPaint localGradientPaint1 = new GradientPaint(0.0F, 0.0F, Color.blue, 0.0F, 0.0F, new Color(0064));  
  62.         GradientPaint localGradientPaint2 = new GradientPaint(0.0F, 0.0F, Color.green, 0.0F, 0.0F, new Color(0640));  
  63.         localStatisticalBarRenderer.setSeriesPaint(0, localGradientPaint1);  
  64.         localStatisticalBarRenderer.setSeriesPaint(1, localGradientPaint2);  
  65.         return localJFreeChart;  
  66.     }  
  67.   
  68.     public static JPanel createDemoPanel() {  
  69.         JFreeChart localJFreeChart = createChart(createDataset());  
  70.         return new ChartPanel(localJFreeChart);  
  71.     }  
  72.   
  73.     public static void main(String[] paramArrayOfString) {  
  74.         StatisticalBarChartDemo1 localStatisticalBarChartDemo1 = new StatisticalBarChartDemo1("Statistical Bar Chart Demo");  
  75.         localStatisticalBarChartDemo1.pack();  
  76.         RefineryUtilities.centerFrameOnScreen(localStatisticalBarChartDemo1);  
  77.         localStatisticalBarChartDemo1.setVisible(true);  
  78.     }  
  79. }  

沒有留言:

張貼留言

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