?? symbolicyplotdemo.java
字號:
/* ======================================
* JFreeChart : a free Java chart library
* ======================================
*
* Project Info: http://www.jfree.org/jfreechart/index.html
* Project Lead: David Gilbert (david.gilbert@object-refinery.com);
*
* (C) Copyright 2000-2003, by Object Refinery Limited and Contributors.
*
* This program is free software; you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Foundation;
* either version 2 of the License, or (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this program;
* if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307, USA.
*
* ----------------------
* SymbolicYPlotDemo.java
* ----------------------
* (C) Copyright 2002, 2003, 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.SymbolicXYToolTipGenerator;
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 {
/**
* 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(String frameTitle,
XYDataset data, String chartTitle,
String xAxisLabel, String yAxisLabel) {
JFreeChart chart = createYSymbolicPlot(chartTitle, xAxisLabel, yAxisLabel, data, true);
chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 1000, 0, Color.green));
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(String frameTitle,
XYDataset data1, XYDataset data2) {
String title = "Animals Overlaid";
String xAxisLabel = "Miles";
String yAxisLabel = "Animal";
// combine the y symbolic values of the two data sets...
String[] combinedYSymbolicValues
= SampleYSymbolicDataset.combineYSymbolicDataset((YisSymbolic) data1,
(YisSymbolic) data2);
// make master dataset...
CombinedDataset data = new CombinedDataset();
data.add(data1);
data.add(data2);
// decompose data...
XYDataset series0 = new SubSeriesDataset(data, 0);
XYDataset series1 = new SubSeriesDataset(data, 1);
XYDataset series2 = new SubSeriesDataset(data, 2);
XYDataset series3 = new SubSeriesDataset(data, 3);
XYDataset series4 = new SubSeriesDataset(data, 4);
XYDataset series5 = new SubSeriesDataset(data, 5);
XYDataset series6 = new SubSeriesDataset(data, 6);
XYDataset series7 = new SubSeriesDataset(data, 7);
// create main plot...
ValueAxis valueAxis = new NumberAxis(xAxisLabel);
SymbolicAxis symbolicAxis = new SymbolicAxis(yAxisLabel, combinedYSymbolicValues);
XYItemRenderer renderer = new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES, null);
XYPlot plot = new XYPlot(series0, valueAxis, symbolicAxis, renderer);
plot.setSecondaryDataset(0, series1);
XYItemRenderer renderer1 = new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES, null);
plot.setSecondaryRenderer(0, renderer1);
plot.setSecondaryDataset(1, series2);
XYItemRenderer renderer2 = new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES, null);
plot.setSecondaryRenderer(1, renderer2);
plot.setSecondaryDataset(2, series3);
XYItemRenderer renderer3 = new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES, null);
plot.setSecondaryRenderer(2, renderer3);
plot.setSecondaryDataset(3, series4);
XYItemRenderer renderer4 = new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES, null);
plot.setSecondaryRenderer(3, renderer4);
plot.setSecondaryDataset(4, series5);
XYItemRenderer renderer5 = new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES, null);
plot.setSecondaryRenderer(4, renderer5);
plot.setSecondaryDataset(5, series6);
XYItemRenderer renderer6 = new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES, null);
plot.setSecondaryRenderer(5, renderer6);
plot.setSecondaryDataset(6, series7);
XYItemRenderer renderer7 = new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES, null);
plot.setSecondaryRenderer(6, renderer7);
// make the chart...
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...
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(String frameTitle,
SampleYSymbolicDataset data1,
SampleYSymbolicDataset data2) {
String title = "Animals Horizontally Combined";
String xAxisLabel = "Miles";
String yAxisLabel = null;
// combine the y symbolic values of the two data sets
String[] combinedYSymbolicValues
= SampleYSymbolicDataset.combineYSymbolicDataset((YisSymbolic) data1,
(YisSymbolic) data2);
// make master dataset...
CombinedDataset data = new CombinedDataset();
data.add(data1);
data.add(data2);
// decompose data...
XYDataset series0 = new SubSeriesDataset(data, 0);
XYDataset series1 = new SubSeriesDataset(data, 1);
XYDataset series2 = new SubSeriesDataset(data, 2);
XYDataset series3 = new SubSeriesDataset(data, 3);
XYDataset series4 = new SubSeriesDataset(data, 4);
XYDataset series5 = new SubSeriesDataset(data, 5);
XYDataset series6 = new SubSeriesDataset(data, 6);
XYDataset series7 = new SubSeriesDataset(data, 7);
// create axes...
ValueAxis valueAxis0 = new NumberAxis(xAxisLabel);
ValueAxis valueAxis1 = new NumberAxis(xAxisLabel);
ValueAxis valueAxis2 = new NumberAxis(xAxisLabel);
ValueAxis valueAxis3 = new NumberAxis(xAxisLabel);
ValueAxis valueAxis4 = new NumberAxis(xAxisLabel);
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -