1 39 40 package org.jfree.chart.demo; 41 42 import java.awt.Font ; 43 44 import org.jfree.chart.ChartPanel; 45 import org.jfree.chart.JFreeChart; 46 import org.jfree.chart.axis.CategoryAxis; 47 import org.jfree.chart.axis.NumberAxis; 48 import org.jfree.chart.axis.ValueAxis; 49 import org.jfree.chart.plot.CategoryPlot; 50 import org.jfree.chart.renderer.CategoryItemRenderer; 51 import org.jfree.chart.renderer.StatisticalBarRenderer; 52 import org.jfree.data.statistics.DefaultStatisticalCategoryDataset; 53 import org.jfree.data.statistics.StatisticalCategoryDataset; 54 import org.jfree.ui.ApplicationFrame; 55 import org.jfree.ui.RefineryUtilities; 56 57 62 public class StatisticalBarChartDemo extends ApplicationFrame { 63 64 69 public StatisticalBarChartDemo(String title) { 70 71 super(title); 72 StatisticalCategoryDataset dataset = createDataset(); 73 74 CategoryAxis xAxis = new CategoryAxis("Type"); 75 xAxis.setLowerMargin(0.01d); xAxis.setUpperMargin(0.01d); xAxis.setCategoryMargin(0.05d); ValueAxis yAxis = new NumberAxis("Value"); 79 80 CategoryItemRenderer renderer = new StatisticalBarRenderer(); 82 CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer); 83 84 JFreeChart chart = new JFreeChart("Statistical Bar Chart Demo", 85 new Font ("Helvetica", Font.BOLD, 14), 86 plot, 87 true); 88 ChartPanel chartPanel = new ChartPanel(chart); 91 chartPanel.setPreferredSize(new java.awt.Dimension (500, 270)); 92 setContentPane(chartPanel); 93 94 } 95 96 107 112 private StatisticalCategoryDataset createDataset() { 113 114 DefaultStatisticalCategoryDataset result = new DefaultStatisticalCategoryDataset(); 115 116 result.add(32.5, 17.9, "Series 1", "Type 1"); 117 result.add(27.8, 11.4, "Series 1", "Type 2"); 118 result.add(29.3, 14.4, "Series 1", "Type 3"); 119 result.add(37.9, 10.3, "Series 1", "Type 4"); 120 121 result.add(22.9, 7.9, "Series 2", "Type 1"); 122 result.add(21.8, 18.4, "Series 2", "Type 2"); 123 result.add(19.3, 12.4, "Series 2", "Type 3"); 124 result.add(30.3, 20.7, "Series 2", "Type 4"); 125 126 result.add(12.5, 10.9, "Series 3", "Type 1"); 127 result.add(24.8, 7.4, "Series 3", "Type 2"); 128 result.add(19.3, 13.4, "Series 3", "Type 3"); 129 result.add(17.1, 10.6, "Series 3", "Type 4"); 130 131 return result; 132 133 } 134 135 140 public static void main(String [] args) { 141 142 StatisticalBarChartDemo demo = new StatisticalBarChartDemo("Statistical Bar Chart Demo"); 143 demo.pack(); 144 RefineryUtilities.centerFrameOnScreen(demo); 145 demo.setVisible(true); 146 147 } 148 149 } 150 | Popular Tags |