1 41 42 package org.jfree.chart.demo; 43 44 import java.awt.Color ; 45 46 import org.jfree.chart.ChartFactory; 47 import org.jfree.chart.ChartPanel; 48 import org.jfree.chart.JFreeChart; 49 import org.jfree.chart.axis.ValueAxis; 50 import org.jfree.chart.plot.PlotOrientation; 51 import org.jfree.chart.plot.XYPlot; 52 import org.jfree.data.XYDataset; 53 import org.jfree.data.XYSeries; 54 import org.jfree.data.XYSeriesCollection; 55 import org.jfree.ui.ApplicationFrame; 56 import org.jfree.ui.RefineryUtilities; 57 58 63 public class XYAreaChartDemo extends ApplicationFrame { 64 65 70 public XYAreaChartDemo(String title) { 71 72 super(title); 73 74 XYSeries series1 = new XYSeries("Random 1"); 75 series1.add(new Integer (1), new Double (500.2)); 76 series1.add(new Integer (2), new Double (694.1)); 77 series1.add(new Integer (3), new Double (-734.4)); 78 series1.add(new Integer (4), new Double (453.2)); 79 series1.add(new Integer (5), new Double (500.2)); 80 series1.add(new Integer (6), new Double (300.7)); 81 series1.add(new Integer (7), new Double (734.4)); 82 series1.add(new Integer (8), new Double (453.2)); 83 84 XYSeries series2 = new XYSeries("Random 2"); 85 series2.add(new Integer (1), new Double (700.2)); 86 series2.add(new Integer (2), new Double (534.1)); 87 series2.add(new Integer (3), new Double (323.4)); 88 series2.add(new Integer (4), new Double (125.2)); 89 series2.add(new Integer (5), new Double (653.2)); 90 series2.add(new Integer (6), new Double (432.7)); 91 series2.add(new Integer (7), new Double (564.4)); 92 series2.add(new Integer (8), new Double (322.2)); 93 94 XYSeriesCollection dataset = new XYSeriesCollection(series1); 95 dataset.addSeries(series2); 96 97 JFreeChart chart = createChart(dataset); 98 99 ChartPanel chartPanel = new ChartPanel(chart); 100 chartPanel.setPreferredSize(new java.awt.Dimension (500, 270)); 101 setContentPane(chartPanel); 102 103 } 104 105 112 private JFreeChart createChart(XYDataset dataset) { 113 114 JFreeChart chart = ChartFactory.createXYAreaChart( 115 "XY Area Chart Demo", 116 "Domain (X)", "Range (Y)", 117 dataset, 118 PlotOrientation.VERTICAL, 119 true, true, false ); 123 124 chart.setBackgroundPaint(Color.white); 125 126 XYPlot plot = chart.getXYPlot(); 127 plot.setBackgroundPaint(Color.lightGray); 129 plot.setForegroundAlpha(0.65f); 130 plot.setDomainGridlinePaint(Color.white); 131 plot.setRangeGridlinePaint(Color.white); 132 133 ValueAxis domainAxis = plot.getDomainAxis(); 134 domainAxis.setTickMarkPaint(Color.black); 135 domainAxis.setLowerMargin(0.0); 136 domainAxis.setUpperMargin(0.0); 137 138 ValueAxis rangeAxis = plot.getRangeAxis(); 139 rangeAxis.setTickMarkPaint(Color.black); 140 141 return chart; 142 143 } 144 145 156 161 public static void main(String [] args) { 162 163 XYAreaChartDemo demo = new XYAreaChartDemo("Area XY Chart Demo"); 164 demo.pack(); 165 RefineryUtilities.centerFrameOnScreen(demo); 166 demo.setVisible(true); 167 168 } 169 170 } 171 | Popular Tags |