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.PlotOrientation; 45 import org.jfree.data.CategoryDataset; 46 import org.jfree.ui.ApplicationFrame; 47 import org.jfree.ui.RefineryUtilities; 48 49 55 public class StackedBarChartDemo1 extends ApplicationFrame { 56 57 62 public StackedBarChartDemo1(String title) { 63 64 super(title); 65 CategoryDataset dataset = createDataset(); 66 JFreeChart chart = createChart(dataset); 67 ChartPanel chartPanel = new ChartPanel(chart); 68 chartPanel.setPreferredSize(new java.awt.Dimension (500, 270)); 69 setContentPane(chartPanel); 70 71 } 72 73 78 private CategoryDataset createDataset() { 79 return DemoDatasetFactory.createCategoryDataset(); 80 } 81 82 89 private JFreeChart createChart(CategoryDataset dataset) { 90 91 JFreeChart chart = ChartFactory.createStackedBarChart( 92 "Stacked Bar Chart Demo 1", "Category", "Value", dataset, PlotOrientation.VERTICAL, true, true, false ); 101 return chart; 102 103 } 104 105 116 121 public static void main(String [] args) { 122 123 StackedBarChartDemo1 demo = new StackedBarChartDemo1("Stacked Bar Chart Demo 1"); 124 demo.pack(); 125 RefineryUtilities.centerFrameOnScreen(demo); 126 demo.setVisible(true); 127 128 } 129 130 } 131 | Popular Tags |