1 40 41 package org.jfree.chart.demo; 42 43 import java.awt.Font ; 44 import java.util.ArrayList ; 45 import java.util.List ; 46 47 import org.jfree.chart.ChartPanel; 48 import org.jfree.chart.JFreeChart; 49 import org.jfree.chart.axis.CategoryAxis; 50 import org.jfree.chart.axis.NumberAxis; 51 import org.jfree.chart.plot.CategoryPlot; 52 import org.jfree.chart.renderer.BoxAndWhiskerRenderer; 53 import org.jfree.data.statistics.BoxAndWhiskerCategoryDataset; 54 import org.jfree.data.statistics.DefaultBoxAndWhiskerCategoryDataset; 55 import org.jfree.ui.ApplicationFrame; 56 import org.jfree.ui.RefineryUtilities; 57 58 63 public class BoxAndWhiskerDemo extends ApplicationFrame { 64 65 70 public BoxAndWhiskerDemo(String title) { 71 72 super(title); 73 74 BoxAndWhiskerCategoryDataset dataset = createSampleDataset(); 75 76 CategoryAxis xAxis = new CategoryAxis("Type"); 77 NumberAxis yAxis = new NumberAxis("Value"); 78 yAxis.setAutoRangeIncludesZero(false); 79 BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer(); 80 CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer); 81 82 JFreeChart chart = new JFreeChart( 83 "Box-and-Whisker Demo", 84 new Font ("SansSerif", Font.BOLD, 14), 85 plot, 86 true 87 ); 88 89 ChartPanel chartPanel = new ChartPanel(chart); 90 chartPanel.setPreferredSize(new java.awt.Dimension (450, 270)); 91 setContentPane(chartPanel); 92 93 } 94 95 100 private BoxAndWhiskerCategoryDataset createSampleDataset() { 101 102 final int SERIES_COUNT = 3; 103 final int CATEGORY_COUNT = 4; 104 final int ENTITY_COUNT = 22; 105 106 DefaultBoxAndWhiskerCategoryDataset dataset = new DefaultBoxAndWhiskerCategoryDataset(); 107 for (int i = 0; i < SERIES_COUNT; i++) { 108 for (int j = 0; j < CATEGORY_COUNT; j++) { 109 List list = new ArrayList (); 110 for (int k = 0; k < ENTITY_COUNT; k++) { 112 double value1 = 10.0 + Math.random() * 3; 113 list.add(new Double (value1)); 114 double value2 = 11.25 + Math.random(); list.add(new Double (value2)); 116 } 117 dataset.add(list, "Series " + i, " Type " + j); 118 } 119 } 120 121 return dataset; 122 } 123 124 135 140 public static void main(String [] args) { 141 142 BoxAndWhiskerDemo demo = new BoxAndWhiskerDemo("Box-and-Whisker Chart Demo"); 143 demo.pack(); 144 RefineryUtilities.centerFrameOnScreen(demo); 145 demo.setVisible(true); 146 147 } 148 149 } 150 | Popular Tags |