1 38 39 package org.jfree.chart.demo; 40 41 import org.jfree.chart.ChartFactory; 42 import org.jfree.chart.ChartPanel; 43 import org.jfree.chart.JFreeChart; 44 import org.jfree.chart.plot.CategoryPlot; 45 import org.jfree.chart.plot.PlotOrientation; 46 import org.jfree.chart.renderer.StackedBarRenderer; 47 import org.jfree.data.CategoryDataset; 48 import org.jfree.ui.ApplicationFrame; 49 import org.jfree.ui.RefineryUtilities; 50 51 57 public class StackedBarChartDemo2 extends ApplicationFrame { 58 59 64 public StackedBarChartDemo2(String title) { 65 66 super(title); 67 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 90 private JFreeChart createChart(CategoryDataset dataset) { 91 92 JFreeChart chart = ChartFactory.createStackedBarChart( 93 "Stacked Bar Chart Demo 2", 94 "Category", "Value", dataset, PlotOrientation.HORIZONTAL, true, true, false ); 102 103 CategoryPlot plot = (CategoryPlot) chart.getPlot(); 104 StackedBarRenderer renderer = (StackedBarRenderer) plot.getRenderer(); 105 renderer.setItemLabelsVisible(true); 106 107 return chart; 108 109 } 110 111 122 127 public static void main(String [] args) { 128 129 StackedBarChartDemo2 demo = new StackedBarChartDemo2("Stacked Bar Chart Demo 2"); 130 demo.pack(); 131 RefineryUtilities.centerFrameOnScreen(demo); 132 demo.setVisible(true); 133 134 } 135 136 } 137 | Popular Tags |