1 37 38 package org.jfree.chart.demo; 39 40 import java.awt.Color ; 41 import java.awt.Font ; 42 import java.awt.GradientPaint ; 43 44 import org.jfree.chart.ChartPanel; 45 import org.jfree.chart.JFreeChart; 46 import org.jfree.chart.TextTitle; 47 import org.jfree.chart.axis.DateAxis; 48 import org.jfree.chart.axis.NumberAxis; 49 import org.jfree.chart.plot.CombinedRangeXYPlot; 50 import org.jfree.chart.plot.XYPlot; 51 import org.jfree.chart.renderer.StandardXYItemRenderer; 52 import org.jfree.chart.renderer.XYBarRenderer; 53 import org.jfree.data.MovingAverage; 54 import org.jfree.data.time.TimeSeries; 55 import org.jfree.data.time.TimeSeriesCollection; 56 import org.jfree.ui.ApplicationFrame; 57 import org.jfree.ui.RefineryUtilities; 58 59 64 public class CombinedXYPlotDemo3 extends ApplicationFrame { 65 66 71 public CombinedXYPlotDemo3(String title) { 72 73 super(title); 74 JFreeChart chart = createCombinedChart(); 75 ChartPanel panel = new ChartPanel(chart, true, true, true, false, true); 76 panel.setPreferredSize(new java.awt.Dimension (500, 270)); 77 setContentPane(panel); 78 79 } 80 81 86 private JFreeChart createCombinedChart() { 87 88 TimeSeriesCollection dataset0 = new TimeSeriesCollection(); 90 TimeSeries eur = DemoDatasetFactory.createEURTimeSeries(); 91 dataset0.addSeries(eur); 92 93 TimeSeriesCollection dataset1 = new TimeSeriesCollection(); 94 TimeSeries mav = MovingAverage.createMovingAverage(eur, "EUR/GBP (30 Day MA)", 30, 30); 95 dataset1.addSeries(eur); 96 dataset1.addSeries(mav); 97 98 TimeSeriesCollection dataset2 = new TimeSeriesCollection(); 99 dataset2.addSeries(eur); 100 101 JFreeChart chart = null; 102 103 NumberAxis valueAxis = new NumberAxis("Value"); 105 valueAxis.setAutoRangeIncludesZero(false); 107 CombinedRangeXYPlot parent = new CombinedRangeXYPlot(valueAxis); 109 110 XYPlot subplot1 = new XYPlot(dataset0, new DateAxis("Date 1"), null, 112 new StandardXYItemRenderer()); 113 parent.add(subplot1, 1); 114 115 XYPlot subplot2 = new XYPlot(dataset1, new DateAxis("Date 2"), null, 117 new StandardXYItemRenderer()); 118 parent.add(subplot2, 1); 119 120 XYPlot subplot3 = new XYPlot(dataset2, new DateAxis("Date 3"), 122 null, new XYBarRenderer(0.20)); 123 parent.add(subplot3, 1); 124 125 chart = new JFreeChart("Demo Chart", JFreeChart.DEFAULT_TITLE_FONT, parent, true); 127 128 TextTitle subtitle = new TextTitle("This is a subtitle", 130 new Font ("SansSerif", Font.BOLD, 12)); 131 chart.addSubtitle(subtitle); 132 chart.setBackgroundPaint(new GradientPaint (0, 0, Color.white, 0, 1000, Color.blue)); 133 return chart; 134 135 } 136 137 148 153 public static void main(String [] args) { 154 155 CombinedXYPlotDemo3 demo = new CombinedXYPlotDemo3("Combined XY Plot Demo 3"); 156 demo.pack(); 157 RefineryUtilities.centerFrameOnScreen(demo); 158 demo.setVisible(true); 159 160 } 161 162 } 163 | Popular Tags |