1 37 38 package org.jfree.chart.demo; 39 40 import java.awt.Font ; 41 42 import org.jfree.chart.ChartPanel; 43 import org.jfree.chart.JFreeChart; 44 import org.jfree.chart.annotations.XYTextAnnotation; 45 import org.jfree.chart.axis.AxisLocation; 46 import org.jfree.chart.axis.NumberAxis; 47 import org.jfree.chart.plot.CombinedDomainXYPlot; 48 import org.jfree.chart.plot.PlotOrientation; 49 import org.jfree.chart.plot.XYPlot; 50 import org.jfree.chart.renderer.StandardXYItemRenderer; 51 import org.jfree.chart.renderer.XYItemRenderer; 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 CombinedXYPlotDemo1 extends ApplicationFrame { 64 65 70 public CombinedXYPlotDemo1(String title) { 71 72 super(title); 73 JFreeChart chart = createCombinedChart(); 74 ChartPanel panel = new ChartPanel(chart, true, true, true, false, true); 75 panel.setPreferredSize(new java.awt.Dimension (500, 270)); 76 setContentPane(panel); 77 78 } 79 80 85 private JFreeChart createCombinedChart() { 86 87 XYDataset data1 = createDataset1(); 89 XYItemRenderer renderer1 = new StandardXYItemRenderer(); 90 NumberAxis rangeAxis1 = new NumberAxis("Range 1"); 91 XYPlot subplot1 = new XYPlot(data1, null, rangeAxis1, renderer1); 92 subplot1.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT); 93 94 XYTextAnnotation annotation = new XYTextAnnotation("Hello!", 50.0, 10000.0); 95 annotation.setFont(new Font ("SansSerif", Font.PLAIN, 9)); 96 annotation.setRotationAngle(Math.PI / 4.0); 97 subplot1.addAnnotation(annotation); 98 99 XYDataset data2 = createDataset2(); 101 XYItemRenderer renderer2 = new StandardXYItemRenderer(); 102 NumberAxis rangeAxis2 = new NumberAxis("Range 2"); 103 rangeAxis2.setAutoRangeIncludesZero(false); 104 XYPlot subplot2 = new XYPlot(data2, null, rangeAxis2, renderer2); 105 subplot2.setRangeAxisLocation(AxisLocation.TOP_OR_LEFT); 106 107 CombinedDomainXYPlot plot = new CombinedDomainXYPlot(new NumberAxis("Domain")); 109 plot.setGap(10.0); 110 111 plot.add(subplot1, 1); 113 plot.add(subplot2, 1); 114 plot.setOrientation(PlotOrientation.VERTICAL); 115 116 return new JFreeChart("CombinedDomainXYPlot Demo", 118 JFreeChart.DEFAULT_TITLE_FONT, plot, true); 119 120 } 121 122 127 private XYDataset createDataset1() { 128 129 XYSeries series1 = new XYSeries("Series 1"); 131 series1.add(10.0, 12353.3); 132 series1.add(20.0, 13734.4); 133 series1.add(30.0, 14525.3); 134 series1.add(40.0, 13984.3); 135 series1.add(50.0, 12999.4); 136 series1.add(60.0, 14274.3); 137 series1.add(70.0, 15943.5); 138 series1.add(80.0, 14845.3); 139 series1.add(90.0, 14645.4); 140 series1.add(100.0, 16234.6); 141 series1.add(110.0, 17232.3); 142 series1.add(120.0, 14232.2); 143 series1.add(130.0, 13102.2); 144 series1.add(140.0, 14230.2); 145 series1.add(150.0, 11235.2); 146 147 XYSeries series2 = new XYSeries("Series 2"); 148 series2.add(10.0, 15000.3); 149 series2.add(20.0, 11000.4); 150 series2.add(30.0, 17000.3); 151 series2.add(40.0, 15000.3); 152 series2.add(50.0, 14000.4); 153 series2.add(60.0, 12000.3); 154 series2.add(70.0, 11000.5); 155 series2.add(80.0, 12000.3); 156 series2.add(90.0, 13000.4); 157 series2.add(100.0, 12000.6); 158 series2.add(110.0, 13000.3); 159 series2.add(120.0, 17000.2); 160 series2.add(130.0, 18000.2); 161 series2.add(140.0, 16000.2); 162 series2.add(150.0, 17000.2); 163 164 XYSeriesCollection collection = new XYSeriesCollection(); 165 collection.addSeries(series1); 166 collection.addSeries(series2); 167 return collection; 168 169 } 170 171 176 private XYDataset createDataset2() { 177 178 XYSeries series2 = new XYSeries("Series 3"); 180 181 series2.add(10.0, 16853.2); 182 series2.add(20.0, 19642.3); 183 series2.add(30.0, 18253.5); 184 series2.add(40.0, 15352.3); 185 series2.add(50.0, 13532.0); 186 series2.add(100.0, 12635.3); 187 series2.add(110.0, 13998.2); 188 series2.add(120.0, 11943.2); 189 series2.add(130.0, 16943.9); 190 series2.add(140.0, 17843.2); 191 series2.add(150.0, 16495.3); 192 series2.add(160.0, 17943.6); 193 series2.add(170.0, 18500.7); 194 series2.add(180.0, 19595.9); 195 196 return new XYSeriesCollection(series2); 197 198 } 199 200 211 216 public static void main(String [] args) { 217 218 CombinedXYPlotDemo1 demo = new CombinedXYPlotDemo1("CombinedDomainXYPlot Demo"); 219 demo.pack(); 220 RefineryUtilities.centerFrameOnScreen(demo); 221 demo.setVisible(true); 222 223 } 224 225 } 226 | Popular Tags |