📄 symbolicyplotdemo.java
字号:
/* =========================================================== * 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.] * * ---------------------- * SymbolicYPlotDemo.java * ---------------------- * (C) Copyright 2002-2004, by Anthony Boulestreau and Contributors. * * Original Author: Anthony Boulestreau; * Contributor(s): David Gilbert (for Object Refinery Limited); * * Changes * ------- * 29-Mar-2002 : Version 1 (AB); * 23-Apr-2002 : Updated to reflect revisions in combined plot classes (DG); * 25-Jun-2002 : Removed unnecessary imports (DG); * 11-Oct-2002 : Fixed errors reported by Checkstyle (DG); * */package org.jfree.chart.demo;import java.awt.Color;import java.awt.GradientPaint;import javax.swing.JFrame;import org.jfree.chart.ChartFrame;import org.jfree.chart.JFreeChart;import org.jfree.chart.axis.NumberAxis;import org.jfree.chart.axis.SymbolicAxis;import org.jfree.chart.axis.ValueAxis;import org.jfree.chart.labels.SymbolicXYItemLabelGenerator;import org.jfree.chart.plot.CombinedDomainXYPlot;import org.jfree.chart.plot.CombinedRangeXYPlot;import org.jfree.chart.plot.XYPlot;import org.jfree.chart.renderer.StandardXYItemRenderer;import org.jfree.chart.renderer.XYItemRenderer;import org.jfree.data.CombinedDataset;import org.jfree.data.SubSeriesDataset;import org.jfree.data.XYDataset;import org.jfree.data.YisSymbolic;import org.jfree.ui.RefineryUtilities;/** * A demonstration application for the symbolic axis plots. * * @author Anthony Boulestreau */public class SymbolicYPlotDemo { // **************************************************************************** // * 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. * // **************************************************************************** /** * Displays an XYPlot with Y symbolic data. * * @param frameTitle the frame title. * @param data the data. * @param chartTitle the chart title. * @param xAxisLabel the x-axis label. * @param yAxisLabel the y-axis label. */ private static void displayYSymbolic(final String frameTitle, final XYDataset data, final String chartTitle, final String xAxisLabel, final String yAxisLabel) { final JFreeChart chart = createYSymbolicPlot( chartTitle, xAxisLabel, yAxisLabel, data, true ); chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 1000, 0, Color.green)); final JFrame frame = new ChartFrame(frameTitle, chart); frame.pack(); RefineryUtilities.positionFrameRandomly(frame); frame.show(); } /** * Create and display an overlaid chart. * * @param frameTitle the frame title. * @param data1 dataset1. * @param data2 dataset2. */ private static void displayYSymbolicOverlaid(final String frameTitle, final XYDataset data1, final XYDataset data2) { final String title = "Animals Overlaid"; final String xAxisLabel = "Miles"; final String yAxisLabel = "Animal"; // combine the y symbolic values of the two data sets... final String[] combinedYSymbolicValues = SampleYSymbolicDataset.combineYSymbolicDataset((YisSymbolic) data1, (YisSymbolic) data2); // make master dataset... final CombinedDataset data = new CombinedDataset(); data.add(data1); data.add(data2); // decompose data... final XYDataset series0 = new SubSeriesDataset(data, 0); final XYDataset series1 = new SubSeriesDataset(data, 1); final XYDataset series2 = new SubSeriesDataset(data, 2); final XYDataset series3 = new SubSeriesDataset(data, 3); final XYDataset series4 = new SubSeriesDataset(data, 4); final XYDataset series5 = new SubSeriesDataset(data, 5); final XYDataset series6 = new SubSeriesDataset(data, 6); final XYDataset series7 = new SubSeriesDataset(data, 7); // create main plot... final ValueAxis valueAxis = new NumberAxis(xAxisLabel); final SymbolicAxis symbolicAxis = new SymbolicAxis(yAxisLabel, combinedYSymbolicValues); final XYItemRenderer renderer = new StandardXYItemRenderer( StandardXYItemRenderer.SHAPES, null ); final XYPlot plot = new XYPlot(series0, valueAxis, symbolicAxis, renderer); plot.setDataset(1, series1); final XYItemRenderer renderer1 = new StandardXYItemRenderer( StandardXYItemRenderer.SHAPES, null ); plot.setRenderer(1, renderer1); plot.setDataset(2, series2); final XYItemRenderer renderer2 = new StandardXYItemRenderer( StandardXYItemRenderer.SHAPES, null ); plot.setRenderer(2, renderer2); plot.setDataset(3, series3); final XYItemRenderer renderer3 = new StandardXYItemRenderer( StandardXYItemRenderer.SHAPES, null ); plot.setRenderer(3, renderer3); plot.setDataset(4, series4); final XYItemRenderer renderer4 = new StandardXYItemRenderer( StandardXYItemRenderer.SHAPES, null ); plot.setRenderer(4, renderer4); plot.setDataset(5, series5); final XYItemRenderer renderer5 = new StandardXYItemRenderer( StandardXYItemRenderer.SHAPES, null ); plot.setRenderer(5, renderer5); plot.setDataset(6, series6); final XYItemRenderer renderer6 = new StandardXYItemRenderer( StandardXYItemRenderer.SHAPES, null ); plot.setRenderer(6, renderer6); plot.setDataset(7, series7); final XYItemRenderer renderer7 = new StandardXYItemRenderer( StandardXYItemRenderer.SHAPES, null ); plot.setRenderer(7, renderer7); // make the chart... final JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, true); chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 0, 1000, Color.blue)); // and present it in a frame... final JFrame frame = new ChartFrame(frameTitle, chart); frame.pack(); RefineryUtilities.positionFrameRandomly(frame); frame.show(); } /** * Create and display a multi XY plot with horizontal layout. * * @param frameTitle the frame title. * @param data1 dataset1. * @param data2 dataset2. */ private static void displayYSymbolicCombinedHorizontally(final String frameTitle, final SampleYSymbolicDataset data1, final SampleYSymbolicDataset data2) { final String title = "Animals Horizontally Combined"; final String xAxisLabel = "Miles"; final String yAxisLabel = null; // combine the y symbolic values of the two data sets final String[] combinedYSymbolicValues = SampleYSymbolicDataset.combineYSymbolicDataset(data1, data2); // make master dataset... final CombinedDataset data = new CombinedDataset(); data.add(data1); data.add(data2); // decompose data... final XYDataset series0 = new SubSeriesDataset(data, 0); final XYDataset series1 = new SubSeriesDataset(data, 1); final XYDataset series2 = new SubSeriesDataset(data, 2); final XYDataset series3 = new SubSeriesDataset(data, 3); final XYDataset series4 = new SubSeriesDataset(data, 4); final XYDataset series5 = new SubSeriesDataset(data, 5); final XYDataset series6 = new SubSeriesDataset(data, 6); final XYDataset series7 = new SubSeriesDataset(data, 7); // create axes... final ValueAxis valueAxis0 = new NumberAxis(xAxisLabel); final ValueAxis valueAxis1 = new NumberAxis(xAxisLabel); final ValueAxis valueAxis2 = new NumberAxis(xAxisLabel); final ValueAxis valueAxis3 = new NumberAxis(xAxisLabel); final ValueAxis valueAxis4 = new NumberAxis(xAxisLabel); final ValueAxis valueAxis5 = new NumberAxis(xAxisLabel); final ValueAxis valueAxis6 = new NumberAxis(xAxisLabel); final ValueAxis valueAxis7 = new NumberAxis(xAxisLabel); final SymbolicAxis symbolicAxis = new SymbolicAxis(yAxisLabel, combinedYSymbolicValues);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -