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.CategoryAxis; 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.chart.renderer.CategoryItemRenderer; 51 import org.jfree.data.CategoryDataset; 52 import org.jfree.data.DatasetUtilities; 53 import org.jfree.ui.ApplicationFrame; 54 import org.jfree.ui.RefineryUtilities; 55 56 62 public class StackedAreaChartDemo extends ApplicationFrame { 63 64 69 public StackedAreaChartDemo(String title) { 70 71 super(title); 72 73 double[][] data = new double[][] { 75 {1.0, 4.0, 3.0, 5.0, 5.0, 7.0, 7.0, 8.0 }, 76 {5.0, 7.0, 6.0, 8.0, 4.0, 4.0, 2.0, 1.0 }, 77 {4.0, 3.0, 2.0, 3.0, 6.0, 3.0, 4.0, 3.0 }}; 78 79 CategoryDataset dataset = DatasetUtilities.createCategoryDataset("Series ", "Type ", data); 80 81 JFreeChart chart = ChartFactory.createStackedAreaChart( 83 "Stacked Area Chart", "Category", "Value", dataset, PlotOrientation.VERTICAL, true, true, 90 false 91 ); 92 93 95 chart.setBackgroundPaint(Color.yellow); 97 98 CategoryPlot plot = chart.getCategoryPlot(); 100 plot.setForegroundAlpha(0.5f); 101 102 CategoryAxis domainAxis = plot.getDomainAxis(); 103 domainAxis.setLowerMargin(0.0); 104 domainAxis.setUpperMargin(0.0); 105 106 NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); 108 rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); 109 110 CategoryItemRenderer renderer = plot.getRenderer(); 111 renderer.setItemLabelsVisible(Boolean.TRUE); 112 113 115 ChartPanel chartPanel = new ChartPanel(chart); 117 chartPanel.setPreferredSize(new java.awt.Dimension (500, 270)); 118 119 setContentPane(chartPanel); 120 121 } 122 123 134 139 public static void main(String [] args) { 140 141 StackedAreaChartDemo demo = new StackedAreaChartDemo("Stacked Area Chart Demo"); 142 demo.pack(); 143 RefineryUtilities.centerFrameOnScreen(demo); 144 demo.setVisible(true); 145 146 } 147 148 } 149 | Popular Tags |