1 37 38 package org.jfree.chart.demo; 39 40 import java.awt.geom.Ellipse2D ; 41 import java.awt.geom.GeneralPath ; 42 import java.awt.geom.Rectangle2D ; 43 44 import org.jfree.chart.ChartFactory; 45 import org.jfree.chart.ChartPanel; 46 import org.jfree.chart.JFreeChart; 47 import org.jfree.chart.StandardLegend; 48 import org.jfree.chart.plot.XYPlot; 49 import org.jfree.chart.renderer.StandardXYItemRenderer; 50 import org.jfree.chart.renderer.XYItemRenderer; 51 import org.jfree.data.XYDataset; 52 import org.jfree.data.time.Day; 53 import org.jfree.data.time.TimeSeries; 54 import org.jfree.data.time.TimeSeriesCollection; 55 import org.jfree.ui.ApplicationFrame; 56 import org.jfree.ui.RefineryUtilities; 57 58 63 public class TimeSeriesDemo9 extends ApplicationFrame { 64 65 71 public TimeSeriesDemo9(String title) { 72 73 super(title); 74 75 String chartTitle = "Test"; 77 XYDataset dataset = createDataset(); 78 79 JFreeChart chart = ChartFactory.createTimeSeriesChart( 80 chartTitle, 81 "Date", 82 "Price Per Unit", 83 dataset, 84 true, 85 true, 86 false 87 ); 88 89 StandardLegend sl = (StandardLegend) chart.getLegend(); 90 sl.setDisplaySeriesShapes(true); 91 92 XYPlot plot = chart.getXYPlot(); 93 XYItemRenderer r = plot.getRenderer(); 94 if (r instanceof StandardXYItemRenderer) { 95 StandardXYItemRenderer renderer = (StandardXYItemRenderer) r; 96 renderer.setPlotShapes(true); 97 renderer.setShapesFilled(true); 98 renderer.setSeriesShape(0, new Ellipse2D.Double (-3.0, -3.0, 6.0, 6.0)); 99 renderer.setSeriesShape(1, new Rectangle2D.Double (-3.0, -3.0, 6.0, 6.0)); 100 GeneralPath s2 = new GeneralPath (); 101 s2.moveTo(0.0f, -3.0f); 102 s2.lineTo(3.0f, 3.0f); 103 s2.lineTo(-3.0f, 3.0f); 104 s2.closePath(); 105 renderer.setSeriesShape(2, s2); 106 GeneralPath s3 = new GeneralPath (); 107 s3.moveTo(-1.0f, -3.0f); 108 s3.lineTo(1.0f, -3.0f); 109 s3.lineTo(1.0f, -1.0f); 110 s3.lineTo(3.0f, -1.0f); 111 s3.lineTo(3.0f, 1.0f); 112 s3.lineTo(1.0f, 1.0f); 113 s3.lineTo(1.0f, 3.0f); 114 s3.lineTo(-1.0f, 3.0f); 115 s3.lineTo(-1.0f, 1.0f); 116 s3.lineTo(-3.0f, 1.0f); 117 s3.lineTo(-3.0f, -1.0f); 118 s3.lineTo(-1.0f, -1.0f); 119 s3.closePath(); 120 renderer.setSeriesShape(3, s3); 121 } 122 123 plot.getDomainAxis().setVisible(false); 124 plot.getRangeAxis().setVisible(false); 125 ChartPanel chartPanel = new ChartPanel(chart); 126 chartPanel.setPreferredSize(new java.awt.Dimension (500, 270)); 127 setContentPane(chartPanel); 128 129 } 130 131 142 147 public XYDataset createDataset() { 148 149 TimeSeriesCollection dataset = new TimeSeriesCollection(); 150 for (int i = 0; i < 4; i++) { 151 dataset.addSeries(createTimeSeries(i, 10)); 152 } 153 return dataset; 154 155 } 156 157 165 public TimeSeries createTimeSeries(int series, int count) { 166 167 TimeSeries result = new TimeSeries("Series " + series , Day.class); 168 169 Day start = new Day(); 170 for (int i = 0; i < count; i++) { 171 result.add(start, Math.random()); 172 start = (Day) start.next(); 173 } 174 175 return result; 176 177 } 178 179 184 public static void main(String [] args) { 185 186 TimeSeriesDemo9 demo = new TimeSeriesDemo9("Time Series Demo 9"); 187 demo.pack(); 188 RefineryUtilities.centerFrameOnScreen(demo); 189 demo.setVisible(true); 190 191 } 192 193 } 194 | Popular Tags |