001 /* ====================================================== 002 * Orson : a free chart beans library based on JFreeChart 003 * ====================================================== 004 * 005 * (C) Copyright 2007, by Object Refinery Limited. 006 * 007 * Project Info: not-yet-released 008 * 009 * This library is free software; you can redistribute it and/or modify it 010 * under the terms of the GNU Lesser General Public License as published by 011 * the Free Software Foundation; either version 2.1 of the License, or 012 * (at your option) any later version. 013 * 014 * This library is distributed in the hope that it will be useful, but 015 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 016 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 017 * License for more details. 018 * 019 * You should have received a copy of the GNU Lesser General Public 020 * License along with this library; if not, write to the Free Software 021 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 022 * USA. 023 * 024 * [Java is a trademark or registered trademark of Sun Microsystems, Inc. 025 * in the United States and other countries.] 026 * 027 */ 028 029 package org.jfree.beans; 030 031 import java.awt.Color; 032 import java.beans.PropertyChangeEvent; 033 034 import org.jfree.chart.ChartFactory; 035 import org.jfree.chart.JFreeChart; 036 import org.jfree.chart.plot.PlotOrientation; 037 import org.jfree.chart.plot.XYPlot; 038 import org.jfree.data.xy.XYDataset; 039 import org.jfree.data.xy.XYSeries; 040 import org.jfree.data.xy.XYSeriesCollection; 041 import org.jfree.ui.RectangleInsets; 042 043 /** 044 * A JavaBean that displays a scatter chart. 045 */ 046 public class JScatterChart extends NumericalXYChart { 047 048 /** 049 * Creates a new pie chart bean. 050 */ 051 public JScatterChart() { 052 super(); 053 } 054 055 /** 056 * Creates a default chart. 057 * 058 * @return The default chart. 059 */ 060 protected JFreeChart createDefaultChart() { 061 XYSeriesCollection dataset = new XYSeriesCollection(); 062 XYSeries s1 = new XYSeries("Series 1"); 063 s1.add(1.0, 5.0); 064 s1.add(2.0, 7.0); 065 s1.add(3.0, 3.0); 066 s1.add(4.0, 6.0); 067 dataset.addSeries(s1); 068 XYSeries s2 = new XYSeries("Series 2"); 069 s2.add(1.2, 3.0); 070 s2.add(2.7, 8.0); 071 s2.add(3.4, 5.0); 072 s2.add(4.3, 1.0); 073 dataset.addSeries(s2); 074 JFreeChart chart = ChartFactory.createScatterPlot( 075 "JScatterChart - Title", "X", "Y", dataset, 076 PlotOrientation.VERTICAL, true, true, false); 077 XYPlot plot = (XYPlot) chart.getPlot(); 078 plot.setBackgroundPaint(Color.lightGray); 079 plot.setDomainGridlinePaint(Color.white); 080 plot.setRangeGridlinePaint(Color.white); 081 plot.setAxisOffset(new RectangleInsets(4, 4, 4, 4)); 082 083 return chart; 084 } 085 086 /** 087 * Returns the dataset used by the chart. 088 * 089 * @return The dataset (possibly <code>null</code>). 090 * 091 * @see #setDataset(XYDataset) 092 */ 093 public XYDataset getDataset() { 094 XYDataset result = null; 095 XYPlot plot = (XYPlot) this.chart.getPlot(); 096 if (plot != null) { 097 result = plot.getDataset(); 098 } 099 return result; 100 } 101 102 /** 103 * Sets the dataset used by the chart and fires a 104 * {@link PropertyChangeEvent} for the <code>dataset</code> property. 105 * 106 * @param dataset the dataset (<code>null</code> permitted). 107 * 108 * @see #getDataset() 109 */ 110 public void setDataset(XYDataset dataset) { 111 XYPlot plot = (XYPlot) this.chart.getPlot(); 112 if (plot != null) { 113 XYDataset old = plot.getDataset(); 114 plot.setDataset(dataset); 115 firePropertyChange("dataset", old, dataset); 116 } 117 } 118 119 }