1 39 40 package org.jfree.chart.demo; 41 42 import java.awt.Color ; 43 import java.awt.Insets ; 44 45 import org.jfree.chart.ChartFactory; 46 import org.jfree.chart.ChartPanel; 47 import org.jfree.chart.JFreeChart; 48 import org.jfree.chart.axis.CategoryAxis; 49 import org.jfree.chart.axis.NumberAxis; 50 import org.jfree.chart.plot.CategoryPlot; 51 import org.jfree.chart.plot.PlotOrientation; 52 import org.jfree.data.DefaultCategoryDataset; 53 import org.jfree.ui.ApplicationFrame; 54 import org.jfree.ui.RefineryUtilities; 55 56 62 public class BarChartDemo6 extends ApplicationFrame { 63 64 69 public BarChartDemo6(String title) { 70 71 super(title); 72 73 DefaultCategoryDataset dataset = new DefaultCategoryDataset(); 75 dataset.addValue(83.0, "First", "Factor 1"); 76 77 JFreeChart chart = ChartFactory.createBarChart( 79 null, "Category", "Score (%)", dataset, PlotOrientation.HORIZONTAL, 84 false, true, 86 false 87 ); 88 89 chart.setBackgroundPaint(Color.yellow); CategoryPlot plot = chart.getCategoryPlot(); 92 plot.setInsets(new Insets (0, 0, 0, 0)); 93 plot.setRangeGridlinesVisible(false); 94 CategoryAxis domainAxis = plot.getDomainAxis(); 95 domainAxis.setLowerMargin(0.20); 96 domainAxis.setUpperMargin(0.20); 97 domainAxis.setVisible(false); 98 NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); 99 rangeAxis.setRange(0.0, 100.0); 100 rangeAxis.setVisible(false); 101 103 ChartPanel chartPanel = new ChartPanel(chart); 105 chartPanel.setPreferredSize(new java.awt.Dimension (500, 270)); 106 setContentPane(chartPanel); 107 108 } 109 110 121 126 public static void main(String [] args) { 127 128 BarChartDemo6 demo = new BarChartDemo6("Minimal Chart Demo"); 129 demo.pack(); 130 RefineryUtilities.centerFrameOnScreen(demo); 131 demo.setVisible(true); 132 133 } 134 135 } 136 | Popular Tags |