1 37 38 package org.jfree.chart.demo; 39 40 import org.jfree.chart.ChartFactory; 41 import org.jfree.chart.ChartPanel; 42 import org.jfree.chart.JFreeChart; 43 import org.jfree.chart.axis.ValueAxis; 44 import org.jfree.chart.labels.StandardCategoryItemLabelGenerator; 45 import org.jfree.chart.plot.CategoryPlot; 46 import org.jfree.chart.plot.PlotOrientation; 47 import org.jfree.chart.renderer.CategoryItemRenderer; 48 import org.jfree.data.CategoryDataset; 49 import org.jfree.ui.ApplicationFrame; 50 import org.jfree.ui.RefineryUtilities; 51 52 58 public class StackedBarChartDemo3 extends ApplicationFrame { 59 60 65 public StackedBarChartDemo3(String title) { 66 67 super(title); 68 CategoryDataset dataset = createDataset(); 69 JFreeChart chart = createChart(dataset); 70 ChartPanel chartPanel = new ChartPanel(chart); 71 chartPanel.setPreferredSize(new java.awt.Dimension (500, 270)); 72 setContentPane(chartPanel); 73 74 } 75 76 81 private CategoryDataset createDataset() { 82 return DemoDatasetFactory.createCategoryDataset(); 83 } 84 85 92 private JFreeChart createChart(CategoryDataset dataset) { 93 94 JFreeChart chart = ChartFactory.createStackedBarChart( 95 "Stacked Bar Chart Demo 3", "Category", "Value", dataset, PlotOrientation.VERTICAL, true, false, false ); 104 CategoryPlot plot = chart.getCategoryPlot(); 105 CategoryItemRenderer renderer = new ExtendedStackedBarRenderer(); 106 renderer.setItemLabelGenerator(new StandardCategoryItemLabelGenerator()); 107 plot.setRenderer(renderer); 108 109 ValueAxis rangeAxis = plot.getRangeAxis(); 110 rangeAxis.setLowerMargin(0.15); 111 rangeAxis.setUpperMargin(0.15); 112 return chart; 113 114 } 115 116 127 132 public static void main(String [] args) { 133 134 StackedBarChartDemo3 demo = new StackedBarChartDemo3("Stacked Bar Chart Demo 3"); 135 demo.pack(); 136 RefineryUtilities.centerFrameOnScreen(demo); 137 demo.setVisible(true); 138 139 } 140 141 } 142 | Popular Tags |