1 38 39 package org.jfree.chart.demo; 40 41 import java.util.ArrayList ; 42 import java.util.Date ; 43 import java.util.List ; 44 45 import org.jfree.chart.ChartFactory; 46 import org.jfree.chart.ChartPanel; 47 import org.jfree.chart.JFreeChart; 48 import org.jfree.chart.plot.PlotOrientation; 49 import org.jfree.data.statistics.BoxAndWhiskerCalculator; 50 import org.jfree.data.statistics.BoxAndWhiskerXYDataset; 51 import org.jfree.data.statistics.DefaultBoxAndWhiskerXYDataset; 52 import org.jfree.date.DateUtilities; 53 import org.jfree.ui.ApplicationFrame; 54 import org.jfree.ui.RefineryUtilities; 55 56 61 public class XYBoxAndWhiskerDemo extends ApplicationFrame { 62 63 68 public XYBoxAndWhiskerDemo(String title) { 69 70 super(title); 71 72 BoxAndWhiskerXYDataset dataset = createSampleDataset(); 73 JFreeChart chart = createChart(dataset); 74 chart.getXYPlot().setOrientation(PlotOrientation.VERTICAL); 75 ChartPanel chartPanel = new ChartPanel(chart); 76 chartPanel.setPreferredSize(new java.awt.Dimension (600, 400)); 77 setContentPane(chartPanel); 78 79 } 80 81 88 private JFreeChart createChart(BoxAndWhiskerXYDataset dataset) { 89 90 JFreeChart chart = ChartFactory.createBoxAndWhiskerChart( 91 "Box-and-Whisker Demo", 92 "Time", 93 "Value", 94 dataset, 95 true 96 ); 97 return chart; 98 99 } 100 101 112 117 public static BoxAndWhiskerXYDataset createSampleDataset() { 118 119 final int ENTITY_COUNT = 14; 120 121 DefaultBoxAndWhiskerXYDataset dataset = new DefaultBoxAndWhiskerXYDataset("Test"); 122 for (int i = 0; i < ENTITY_COUNT; i++) { 123 Date date = DateUtilities.createDate(2003, 7, i + 1, 12, 0); 124 List values = new ArrayList (); 125 for (int j = 0; j < 10; j++) { 126 values.add(new Double (10.0 + Math.random() * 10.0)); 127 values.add(new Double (13.0 + Math.random() * 4.0)); 128 } 129 dataset.add(date, BoxAndWhiskerCalculator.calculateBoxAndWhiskerStatistics(values)); 130 131 } 132 133 return dataset; 134 } 135 136 141 public static void main(String [] args) { 142 143 XYBoxAndWhiskerDemo demo = new XYBoxAndWhiskerDemo("Box-and-Whisker Demo"); 144 demo.pack(); 145 RefineryUtilities.centerFrameOnScreen(demo); 146 demo.setVisible(true); 147 148 } 149 150 } 151 152 | Popular Tags |