1 38 39 package org.jfree.chart.demo; 40 41 import java.awt.Color ; 42 43 import org.jfree.chart.ChartFactory; 44 import org.jfree.chart.ChartPanel; 45 import org.jfree.chart.JFreeChart; 46 import org.jfree.chart.plot.CategoryPlot; 47 import org.jfree.chart.plot.PlotOrientation; 48 import org.jfree.chart.renderer.MinMaxCategoryRenderer; 49 import org.jfree.data.DefaultCategoryDataset; 50 import org.jfree.ui.ApplicationFrame; 51 import org.jfree.ui.RefineryUtilities; 52 53 58 public class MinMaxCategoryPlotDemo extends ApplicationFrame { 59 60 65 public MinMaxCategoryPlotDemo(String title) { 66 67 super(title); 68 69 DefaultCategoryDataset dataset = new DefaultCategoryDataset(); 71 dataset.addValue(1.0, "First", "Category 1"); 72 dataset.addValue(4.0, "First", "Category 2"); 73 dataset.addValue(3.0, "First", "Category 3"); 74 dataset.addValue(5.0, "First", "Category 4"); 75 dataset.addValue(5.0, "First", "Category 5"); 76 dataset.addValue(7.0, "First", "Category 6"); 77 dataset.addValue(7.0, "First", "Category 7"); 78 dataset.addValue(8.0, "First", "Category 8"); 79 dataset.addValue(5.0, "Second", "Category 1"); 80 dataset.addValue(7.0, "Second", "Category 2"); 81 dataset.addValue(6.0, "Second", "Category 3"); 82 dataset.addValue(8.0, "Second", "Category 4"); 83 dataset.addValue(4.0, "Second", "Category 5"); 84 dataset.addValue(4.0, "Second", "Category 6"); 85 dataset.addValue(2.0, "Second", "Category 7"); 86 dataset.addValue(1.0, "Second", "Category 8"); 87 dataset.addValue(4.0, "Third", "Category 1"); 88 dataset.addValue(3.0, "Third", "Category 2"); 89 dataset.addValue(2.0, "Third", "Category 3"); 90 dataset.addValue(3.0, "Third", "Category 4"); 91 dataset.addValue(6.0, "Third", "Category 5"); 92 dataset.addValue(3.0, "Third", "Category 6"); 93 dataset.addValue(4.0, "Third", "Category 7"); 94 dataset.addValue(3.0, "Third", "Category 8"); 95 96 JFreeChart chart = ChartFactory.createBarChart( 98 "Min/Max Category Plot", "Category", "Value", dataset, PlotOrientation.VERTICAL, 103 true, true, false ); 107 108 110 chart.setBackgroundPaint(Color.yellow); 112 113 CategoryPlot plot = chart.getCategoryPlot(); 115 plot.setRenderer(new MinMaxCategoryRenderer()); 116 118 ChartPanel chartPanel = new ChartPanel(chart); 120 chartPanel.setPreferredSize(new java.awt.Dimension (500, 270)); 121 setContentPane(chartPanel); 122 123 } 124 125 136 141 public static void main(String [] args) { 142 143 MinMaxCategoryPlotDemo demo = new MinMaxCategoryPlotDemo("Min/Max Category Chart Demo"); 144 demo.pack(); 145 RefineryUtilities.centerFrameOnScreen(demo); 146 demo.setVisible(true); 147 148 } 149 150 } 151 | Popular Tags |