JFreeChart: XY Line And Shape Renderer Demo
/* ===========================================================
* JFreeChart : a free chart library for the Java(tm) platform
* ===========================================================
*
* (C) Copyright 2000-2004, 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., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307, USA.
*
* [Java is a trademark or registered trademark of Sun Microsystems, Inc.
* in the United States and other countries.]
*
* -------------------------------
* XYLineAndShapeRendererDemo.java
* -------------------------------
* (C) Copyright 2004, by Object Refinery Limited and Contributors.
*
* Original Author: David Gilbert (for Object Refinery Limited);
* Contributor(s): -;
*
* $Id: XYLineAndShapeRendererDemo.java,v 1.1 2004/06/07 10:37:49 mungady Exp $
*
* Changes
* -------
* 07-Jun-2004 : Version 1 (DG);
*
*/
package org.jfree.chart.demo;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
import org.jfree.data.xy.XYDataset;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;
import org.jfree.ui.ApplicationFrame;
import org.jfree.ui.RefineryUtilities;
/**
* A simple demonstration of the {@link XYLineAndShapeRenderer} class.
*/
public class XYLineAndShapeRendererDemo extends ApplicationFrame {
/**
* Constructs the demo application.
*
* @param title the frame title.
*/
public XYLineAndShapeRendererDemo(final String title) {
super(title);
XYDataset dataset = createSampleDataset();
JFreeChart chart = ChartFactory.createXYLineChart(
title,
"X",
"Y",
dataset,
PlotOrientation.VERTICAL,
true,
false,
false
);
XYPlot plot = (XYPlot) chart.getPlot();
XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
renderer.setSeriesLinesVisible(0, true);
renderer.setSeriesShapesVisible(0, false);
renderer.setSeriesLinesVisible(1, false);
renderer.setSeriesShapesVisible(1, true);
plot.setRenderer(renderer);
final ChartPanel chartPanel = new ChartPanel(chart);
chartPanel.setPreferredSize(new java.awt.Dimension(500, 300));
setContentPane(chartPanel);
}
/**
* Creates a sample dataset.
*
* @return A dataset.
*/
private XYDataset createSampleDataset() {
XYSeries series1 = new XYSeries("Series 1");
series1.add(1.0, 3.3);
series1.add(2.0, 4.4);
series1.add(3.0, 1.7);
XYSeries series2 = new XYSeries("Series 2");
series2.add(1.0, 7.3);
series2.add(2.0, 6.8);
series2.add(3.0, 9.6);
series2.add(4.0, 5.6);
XYSeriesCollection dataset = new XYSeriesCollection();
dataset.addSeries(series1);
dataset.addSeries(series2);
return dataset;
}
// ****************************************************************************
// * JFREECHART DEVELOPER GUIDE *
// * The JFreeChart Developer Guide, written by David Gilbert, is available *
// * to purchase from Object Refinery Limited: *
// * *
// * http://www.object-refinery.com/jfreechart/guide.html *
// * *
// * Sales are used to provide funding for the JFreeChart project - please *
// * support us so that we can continue developing free software. *
// ****************************************************************************
/**
* Starting point for the demonstration application.
*
* @param args ignored.
*/
public static void main(final String[] args) {
final XYLineAndShapeRendererDemo demo = new XYLineAndShapeRendererDemo(
"XYLineAndShapeRenderer Demo"
);
demo.pack();
RefineryUtilities.centerFrameOnScreen(demo);
demo.setVisible(true);
}
}
jfreechart-1.0.0-rc1.zip( 3,559 k)Related examples in the same category