|
From: Thies <tg...@us...> - 2007-06-06 17:18:03
|
Update of /cvsroot/tail/Tail/src/java/net/sf/tail/graphics In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv12268/src/java/net/sf/tail/graphics Added Files: TimeSeriesChartDemo1.java Log Message: teste BEM básico da parte gráfica... --- NEW FILE: TimeSeriesChartDemo1.java --- /* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2005, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Java is a trademark or registered trademark of Sun Microsystems, Inc. * in the United States and other countries.] * * ------------------------- * TimeSeriesChartDemo1.java * ------------------------- * (C) Copyright 2003-2005, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): ; * * $Id: TimeSeriesChartDemo1.java,v 1.1 2007/06/06 17:18:02 tgthies Exp $ * * Changes * ------- * 09-Mar-2005 : Version 1, copied from the demo collection that ships with * the JFreeChart Developer Guide (DG); * */ package net.sf.tail.graphics; import java.awt.Color; import java.text.SimpleDateFormat; import javax.swing.JPanel; import net.sf.tail.Indicator; import net.sf.tail.indicator.tracker.SMAIndicator; import net.sf.tail.sample.SampleIndicator; import org.jfree.chart.ChartFactory; import org.jfree.chart.ChartPanel; import org.jfree.chart.JFreeChart; import org.jfree.chart.axis.DateAxis; import org.jfree.chart.plot.XYPlot; import org.jfree.chart.renderer.xy.XYItemRenderer; import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer; import org.jfree.data.time.Month; import org.jfree.data.time.TimeSeries; import org.jfree.data.time.TimeSeriesCollection; import org.jfree.data.xy.XYDataset; import org.jfree.ui.ApplicationFrame; import org.jfree.ui.RectangleInsets; import org.jfree.ui.RefineryUtilities; /** * An example of a time series chart. For the most part, default settings are * used, except that the renderer is modified to show filled shapes (as well as * lines) at each data point. */ public class TimeSeriesChartDemo1 extends ApplicationFrame { /** * */ private static final long serialVersionUID = 1L; private final static String legenda = "Valor"; private final static String legenda2 = "SMA"; private final static SampleIndicator sample = new SampleIndicator(new double[]{10.4, 10.7, 9.1, 8.7, 6.3, 9.3, 10.8, 11.1, 12.5, 14.0}); private final static Indicator<Double> sma = new SMAIndicator(sample, 5); private final static TimeSeries s1 = new TimeSeries(legenda, Month.class); private final static TimeSeries s2 = new TimeSeries(legenda2, Month.class); /** * A demonstration application showing how to create a simple time series * chart. This example uses monthly data. * * @param title the frame title. */ public TimeSeriesChartDemo1(String title) { super(title); ChartPanel chartPanel = (ChartPanel) createDemoPanel(); chartPanel.setPreferredSize(new java.awt.Dimension(800, 600)); chartPanel.setMouseZoomable(true, false); setContentPane(chartPanel); } /** * Creates a chart. * * @param dataset a dataset. * * @return A chart. */ private static JFreeChart createChart(XYDataset dataset) { JFreeChart chart = ChartFactory.createTimeSeriesChart( "Valor teste e seu SMA", // title "Data", // x-axis label "Valor", // y-axis label dataset, // data true, // create legend? true, // generate tooltips? false // generate URLs? ); chart.setBackgroundPaint(Color.white); XYPlot plot = (XYPlot) chart.getPlot(); plot.setBackgroundPaint(Color.BLACK); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); plot.setAxisOffset(new RectangleInsets(1.0, 1.0, 1.0, 1.0)); plot.setDomainCrosshairVisible(true); plot.setRangeCrosshairVisible(true); XYItemRenderer r = plot.getRenderer(); if (r instanceof XYLineAndShapeRenderer) { XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r; renderer.setBaseShapesVisible(true); renderer.setBaseShapesFilled(true); } DateAxis axis = (DateAxis) plot.getDomainAxis(); axis.setDateFormatOverride(new SimpleDateFormat("dd/MM hh:mm")); return chart; } /** * Creates a dataset, consisting of two series of monthly data. * * @return The dataset. */ private static XYDataset createDataset() { // SampleTimeSeries ts = new SampleTimeSeries(); // // ClosePriceIndicator sample = new ClosePriceIndicator(ts); for (int i = 0; i<10; i++) { s1.add(new Month((i%12)+1, 2007+(i/12)), sample.getValue(i).doubleValue()); s2.add(new Month((i%12)+1, 2007+(i/12)), sma.getValue(i).doubleValue()); } TimeSeriesCollection dataset = new TimeSeriesCollection(); dataset.addSeries(s1); dataset.addSeries(s2); //dataset.setDomainIsPointsInTime(true); return dataset; } /** * Creates a panel for the demo (used by SuperDemo.java). * * @return A panel. */ public static JPanel createDemoPanel() { JFreeChart chart = createChart(createDataset()); return new ChartPanel(chart); } /** * Starting point for the demonstration application. * * @param args ignored. */ public static void main(String[] args) { TimeSeriesChartDemo1 demo = new TimeSeriesChartDemo1( "Time Series Chart Demo 1" ); demo.pack(); RefineryUtilities.centerFrameOnScreen(demo); demo.setVisible(true); } } |