程式扎記: [ Java 代碼範本 ] JFreechart: Barcharts > Stacked > StackedBarChart3DDemo4

標籤

2014年2月9日 星期日

[ Java 代碼範本 ] JFreechart: Barcharts > Stacked > StackedBarChart3DDemo4

Code: 
Used libraries: 
* jfreechart-1.0.14.jar
* jcommon-1.0.17.jar
* jfreechart-1.0.14-swt.jar

  1. package Barcharts.stacked;  
  2.   
  3. import java.awt.Dimension;  
  4. import java.text.DecimalFormat;  
  5. import java.text.NumberFormat;  
  6.   
  7. import javax.swing.JPanel;  
  8.   
  9. import org.jfree.chart.ChartFactory;  
  10. import org.jfree.chart.ChartPanel;  
  11. import org.jfree.chart.JFreeChart;  
  12. import org.jfree.chart.labels.ItemLabelAnchor;  
  13. import org.jfree.chart.labels.ItemLabelPosition;  
  14. import org.jfree.chart.labels.StandardCategoryItemLabelGenerator;  
  15. import org.jfree.chart.plot.CategoryPlot;  
  16. import org.jfree.chart.plot.PlotOrientation;  
  17. import org.jfree.chart.renderer.category.StackedBarRenderer3D;  
  18. import org.jfree.data.category.CategoryDataset;  
  19. import org.jfree.data.category.DefaultCategoryDataset;  
  20. import org.jfree.ui.ApplicationFrame;  
  21. import org.jfree.ui.RefineryUtilities;  
  22. import org.jfree.ui.TextAnchor;  
  23.   
  24. public class StackedBarChart3DDemo4 extends ApplicationFrame  
  25. {  
  26.   
  27.     public StackedBarChart3DDemo4(String s)  
  28.     {  
  29.             super(s);  
  30.             JPanel jpanel = createDemoPanel();  
  31.             jpanel.setPreferredSize(new Dimension(500270));  
  32.             setContentPane(jpanel);  
  33.     }  
  34.   
  35.     public static CategoryDataset createDataset()  
  36.     {  
  37.             DefaultCategoryDataset defaultcategorydataset = new DefaultCategoryDataset();  
  38.             defaultcategorydataset.addValue(10D, "Series 1""C1");  
  39.             defaultcategorydataset.addValue(5D, "Series 1""C2");  
  40.             defaultcategorydataset.addValue(6D, "Series 1""C3");  
  41.             defaultcategorydataset.addValue(7D, "Series 1""C4");  
  42.             defaultcategorydataset.addValue(8D, "Series 1""C5");  
  43.             defaultcategorydataset.addValue(9D, "Series 1""C6");  
  44.             defaultcategorydataset.addValue(10D, "Series 1""C7");  
  45.             defaultcategorydataset.addValue(11D, "Series 1""C8");  
  46.             defaultcategorydataset.addValue(3D, "Series 1""C9");  
  47.             defaultcategorydataset.addValue(4D, "Series 2""C1");  
  48.             defaultcategorydataset.addValue(7D, "Series 2""C2");  
  49.             defaultcategorydataset.addValue(17D, "Series 2""C3");  
  50.             defaultcategorydataset.addValue(15D, "Series 2""C4");  
  51.             defaultcategorydataset.addValue(6D, "Series 2""C5");  
  52.             defaultcategorydataset.addValue(8D, "Series 2""C6");  
  53.             defaultcategorydataset.addValue(9D, "Series 2""C7");  
  54.             defaultcategorydataset.addValue(13D, "Series 2""C8");  
  55.             defaultcategorydataset.addValue(7D, "Series 2""C9");  
  56.             defaultcategorydataset.addValue(15D, "Series 3""C1");  
  57.             defaultcategorydataset.addValue(14D, "Series 3""C2");  
  58.             defaultcategorydataset.addValue(12D, "Series 3""C3");  
  59.             defaultcategorydataset.addValue(11D, "Series 3""C4");  
  60.             defaultcategorydataset.addValue(10D, "Series 3""C5");  
  61.             defaultcategorydataset.addValue(0.0D, "Series 3""C6");  
  62.             defaultcategorydataset.addValue(7D, "Series 3""C7");  
  63.             defaultcategorydataset.addValue(9D, "Series 3""C8");  
  64.             defaultcategorydataset.addValue(11D, "Series 3""C9");  
  65.             defaultcategorydataset.addValue(14D, "Series 4""C1");  
  66.             defaultcategorydataset.addValue(3D, "Series 4""C2");  
  67.             defaultcategorydataset.addValue(7D, "Series 4""C3");  
  68.             defaultcategorydataset.addValue(0.0D, "Series 4""C4");  
  69.             defaultcategorydataset.addValue(9D, "Series 4""C5");  
  70.             defaultcategorydataset.addValue(6D, "Series 4""C6");  
  71.             defaultcategorydataset.addValue(7D, "Series 4""C7");  
  72.             defaultcategorydataset.addValue(9D, "Series 4""C8");  
  73.             defaultcategorydataset.addValue(10D, "Series 4""C9");  
  74.             return defaultcategorydataset;  
  75.     }  
  76.   
  77.     private static JFreeChart createChart(CategoryDataset categorydataset)  
  78.     {  
  79.             JFreeChart jfreechart = ChartFactory.createStackedBarChart3D("Stacked Bar Chart 3D Demo 4""Category""Value", categorydataset, PlotOrientation.HORIZONTAL, truetruefalse);  
  80.             CategoryPlot categoryplot = (CategoryPlot)jfreechart.getPlot();  
  81.             StackedBarRenderer3D stackedbarrenderer3d = (StackedBarRenderer3D)categoryplot.getRenderer();  
  82.             stackedbarrenderer3d.setRenderAsPercentages(true);  
  83.             stackedbarrenderer3d.setDrawBarOutline(false);  
  84.             stackedbarrenderer3d.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator("{3}", NumberFormat.getIntegerInstance(), newDecimalFormat("0.0%")));  
  85.             stackedbarrenderer3d.setBaseItemLabelsVisible(true);  
  86.             stackedbarrenderer3d.setBasePositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER));  
  87.             stackedbarrenderer3d.setBaseNegativeItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER));  
  88.             return jfreechart;  
  89.     }  
  90.   
  91.     public static JPanel createDemoPanel()  
  92.     {  
  93.             JFreeChart jfreechart = createChart(createDataset());  
  94.             return new ChartPanel(jfreechart);  
  95.     }  
  96.   
  97.     public static void main(String args[])  
  98.     {  
  99.             StackedBarChart3DDemo4 stackedbarchart3ddemo4 = new StackedBarChart3DDemo4("Stacked Bar Chart 3D Demo 4");  
  100.             stackedbarchart3ddemo4.pack();  
  101.             RefineryUtilities.centerFrameOnScreen(stackedbarchart3ddemo4);  
  102.             stackedbarchart3ddemo4.setVisible(true);  
  103.     }  
  104. }  
UI: 

沒有留言:

張貼留言

網誌存檔

關於我自己

我的相片
Where there is a will, there is a way!