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.axis.AxisLocation; 47 import org.jfree.chart.axis.NumberAxis; 48 import org.jfree.chart.plot.CategoryPlot; 49 import org.jfree.chart.plot.PlotOrientation; 50 import org.jfree.data.CategoryDataset; 51 import org.jfree.data.DatasetUtilities; 52 import org.jfree.ui.ApplicationFrame; 53 import org.jfree.ui.RefineryUtilities; 54 55 60 public class BarChartDemo2 extends ApplicationFrame { 61 62 67 public BarChartDemo2(String title) { 68 69 super(title); 70 71 double[][] data = new double[][] { 73 {1.0, 43.0, 35.0, 58.0, 54.0, 77.0, 71.0, 89.0}, 74 {54.0, 75.0, 63.0, 83.0, 43.0, 46.0, 27.0, 13.0}, 75 {41.0, 33.0, 22.0, 34.0, 62.0, 32.0, 42.0, 34.0} 76 }; 77 78 CategoryDataset dataset = DatasetUtilities.createCategoryDataset( 79 "Series ", 80 "Factor ", 81 data 82 ); 83 84 JFreeChart chart = ChartFactory.createBarChart( 86 "Bar Chart Demo 2", "Category", "Score (%)", dataset, PlotOrientation.HORIZONTAL, 91 true, true, 93 false 94 ); 95 96 98 chart.setBackgroundPaint(Color.lightGray); 100 101 CategoryPlot plot = chart.getCategoryPlot(); 103 plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT); 104 105 NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); 107 rangeAxis.setRange(0.0, 100.0); 108 rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); 109 110 112 ChartPanel chartPanel = new ChartPanel(chart); 114 chartPanel.setPreferredSize(new java.awt.Dimension (500, 270)); 115 setContentPane(chartPanel); 116 117 } 118 119 130 135 public static void main(String [] args) { 136 137 BarChartDemo2 demo = new BarChartDemo2("Bar Chart Demo 2"); 138 demo.pack(); 139 RefineryUtilities.centerFrameOnScreen(demo); 140 demo.setVisible(true); 141 142 } 143 144 } 145 | Popular Tags |