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 CombinedXYPlotDemo5 extends ApplicationFrame { 65 66 71 public CombinedXYPlotDemo5(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 subplot1.setDomainCrosshairVisible(true); 114 subplot1.setRangeCrosshairVisible(true); 115 parent.add(subplot1, 1); 116 117 XYPlot subplot2 = new XYPlot(dataset1, new DateAxis("Date 2"), null, 119 new StandardXYItemRenderer()); 120 subplot2.setDomainCrosshairVisible(true); 121 subplot2.setRangeCrosshairVisible(true); 122 parent.add(subplot2, 1); 123 124 XYPlot subplot3 = new XYPlot(dataset2, new DateAxis("Date 3"), 126 null, new XYBarRenderer(0.20)); 127 subplot3.setDomainCrosshairVisible(true); 128 subplot3.setRangeCrosshairVisible(true); 129 parent.add(subplot3, 1); 130 131 chart = new JFreeChart("Demo Chart", JFreeChart.DEFAULT_TITLE_FONT, parent, true); 133 134 TextTitle subtitle = new TextTitle("This is a subtitle", 136 new Font ("SansSerif", Font.BOLD, 12)); 137 chart.addSubtitle(subtitle); 138 chart.setBackgroundPaint(new GradientPaint (0, 0, Color.white, 0, 1000, Color.blue)); 139 return chart; 140 141 } 142 143 148 public static void main(String [] args) { 149 150 CombinedXYPlotDemo5 demo = new CombinedXYPlotDemo5("Combined XY Plot Demo 5"); 151 demo.pack(); 152 RefineryUtilities.centerFrameOnScreen(demo); 153 demo.setVisible(true); 154 155 } 156 157 } 158 | Popular Tags |