1 38 39 package org.jfree.chart.demo; 40 41 import java.awt.Color ; 42 import java.text.DateFormat ; 43 44 import org.jfree.chart.ChartFactory; 45 import org.jfree.chart.ChartPanel; 46 import org.jfree.chart.JFreeChart; 47 import org.jfree.chart.StandardLegend; 48 import org.jfree.chart.axis.DateAxis; 49 import org.jfree.chart.labels.CategoryItemLabelGenerator; 50 import org.jfree.chart.labels.StandardCategoryItemLabelGenerator; 51 import org.jfree.chart.plot.CategoryPlot; 52 import org.jfree.chart.plot.PlotOrientation; 53 import org.jfree.chart.renderer.CategoryItemRenderer; 54 import org.jfree.chart.renderer.LineAndShapeRenderer; 55 import org.jfree.data.DefaultCategoryDataset; 56 import org.jfree.data.time.Day; 57 import org.jfree.date.SerialDate; 58 import org.jfree.ui.ApplicationFrame; 59 import org.jfree.ui.RefineryUtilities; 60 61 66 public class EventFrequencyDemo extends ApplicationFrame { 67 68 73 public EventFrequencyDemo(String title) { 74 75 super(title); 76 77 DefaultCategoryDataset dataset = new DefaultCategoryDataset(); 79 80 Day d1 = new Day(12, SerialDate.JUNE, 2002); 82 Day d2 = new Day(14, SerialDate.JUNE, 2002); 83 Day d3 = new Day(15, SerialDate.JUNE, 2002); 84 Day d4 = new Day(10, SerialDate.JULY, 2002); 85 Day d5 = new Day(20, SerialDate.JULY, 2002); 86 Day d6 = new Day(22, SerialDate.AUGUST, 2002); 87 88 dataset.setValue(new Long (d1.getMiddleMillisecond()), "Series 1", "Requirement 1"); 89 dataset.setValue(new Long (d1.getMiddleMillisecond()), "Series 1", "Requirement 2"); 90 dataset.setValue(new Long (d2.getMiddleMillisecond()), "Series 1", "Requirement 3"); 91 dataset.setValue(new Long (d3.getMiddleMillisecond()), "Series 2", "Requirement 1"); 92 dataset.setValue(new Long (d4.getMiddleMillisecond()), "Series 2", "Requirement 3"); 93 dataset.setValue(new Long (d5.getMiddleMillisecond()), "Series 3", "Requirement 2"); 94 dataset.setValue(new Long (d6.getMiddleMillisecond()), "Series 1", "Requirement 4"); 95 96 JFreeChart chart = ChartFactory.createBarChart( 98 "Event Frequency Demo", "Category", "Value", dataset, PlotOrientation.HORIZONTAL, 103 true, true, false ); 107 108 110 chart.setBackgroundPaint(new Color (0xFF, 0xFF, 0xCC)); 112 113 StandardLegend legend = (StandardLegend) chart.getLegend(); 114 legend.setDisplaySeriesShapes(true); 115 116 CategoryPlot plot = chart.getCategoryPlot(); 118 plot.setRangeAxis(new DateAxis("Date")); 119 CategoryItemLabelGenerator labelGenerator 120 = new StandardCategoryItemLabelGenerator(DateFormat.getDateInstance()); 121 CategoryItemRenderer renderer = new LineAndShapeRenderer(LineAndShapeRenderer.SHAPES); 122 renderer.setItemLabelGenerator(labelGenerator); 123 plot.setRenderer(renderer); 124 125 136 138 ChartPanel chartPanel = new ChartPanel(chart); 140 chartPanel.setPreferredSize(new java.awt.Dimension (500, 270)); 141 setContentPane(chartPanel); 142 143 } 144 145 150 public static void main(String [] args) { 151 152 EventFrequencyDemo demo = new EventFrequencyDemo("Event Frequency Demo"); 153 demo.pack(); 154 RefineryUtilities.centerFrameOnScreen(demo); 155 demo.setVisible(true); 156 157 } 158 159 } 160 | Popular Tags |