spiderwebplot.java

来自「JfreeChart 常用图表例子」· Java 代码 · 共 1,150 行 · 第 1/3 页

JAVA
1,150
字号
/* =========================================================== * 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., 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.] *  * ------------------ * SpiderWebPlot.java * ------------------ * (C) Copyright 2005, by Heaps of Flavour Pty Ltd. * * Company Info:  http://www.i4-talent.com * * Original Author:  Don Elliott; * Contributor(s):   David Gilbert (for Object Refinery Limited); * * $Id: SpiderWebPlot.java,v 1.11 2005/05/19 14:03:40 mungady Exp $ * * Changes (from 28-Jan-2005) * -------------------------- * 28-Jan-2005 : First cut - missing a few features - still to do: *                           - needs tooltips/URL/label generator functions *                           - ticks on axes / background grid? * 31-Jan-2005 : Renamed SpiderWebPlot, added label generator support, and  *               reformatted for consistency with other source files in  *               JFreeChart (DG); * 20-Apr-2005 : Renamed CategoryLabelGenerator  *               --> CategoryItemLabelGenerator (DG); * 05-May-2005 : Updated draw() method parameters (DG); *  */package org.jfree.chart.plot;import java.awt.AlphaComposite;import java.awt.BasicStroke;import java.awt.Color;import java.awt.Composite;import java.awt.Font;import java.awt.Graphics2D;import java.awt.Paint;import java.awt.Polygon;import java.awt.Shape;import java.awt.Stroke;import java.awt.font.FontRenderContext;import java.awt.font.LineMetrics;import java.awt.geom.Arc2D;import java.awt.geom.Ellipse2D;import java.awt.geom.Line2D;import java.awt.geom.Point2D;import java.awt.geom.Rectangle2D;import java.io.Serializable;import java.util.Iterator;import java.util.List;import org.jfree.chart.LegendItem;import org.jfree.chart.LegendItemCollection;import org.jfree.chart.event.PlotChangeEvent;import org.jfree.chart.labels.CategoryItemLabelGenerator;import org.jfree.chart.labels.StandardCategoryItemLabelGenerator;import org.jfree.data.category.CategoryDataset;import org.jfree.data.general.DatasetUtilities;import org.jfree.ui.RectangleInsets;import org.jfree.util.PaintList;import org.jfree.util.Rotation;import org.jfree.util.StrokeList;import org.jfree.util.TableOrder;/** * A plot that displays data from a {@link CategoryDataset} in the form of a  * "spider web".  Multiple series can be plotted on the same axis to allow  * easy comparison. */public class SpiderWebPlot extends Plot implements Cloneable, Serializable {        /** For serialization. */    private static final long serialVersionUID = -5376340422031599463L;        /** The default head radius percent (currently 1%). */    public static final double DEFAULT_HEAD = 0.01;    /** The default axis label gap (currently 10%). */    public static final double DEFAULT_AXIS_LABEL_GAP = 0.10;     /** The default interior gap. */    public static final double DEFAULT_INTERIOR_GAP = 0.25;    /** The maximum interior gap (currently 40%). */    public static final double MAX_INTERIOR_GAP = 0.40;    /** The default starting angle for the radar chart axes. */    public static final double DEFAULT_START_ANGLE = 90.0;    /** The default series label font. */    public static final Font   DEFAULT_LABEL_FONT = new Font(        "SansSerif", Font.PLAIN, 10    );        /** The default series label paint. */    public static final Paint  DEFAULT_LABEL_PAINT = Color.black;    /** The default series label background paint. */    public static final Paint  DEFAULT_LABEL_BACKGROUND_PAINT         = new Color(255, 255, 192);    /** The default series label outline paint. */    public static final Paint  DEFAULT_LABEL_OUTLINE_PAINT = Color.black;    /** The default series label outline stroke. */    public static final Stroke DEFAULT_LABEL_OUTLINE_STROKE         = new BasicStroke(0.5f);    /** The default series label shadow paint. */    public static final Paint  DEFAULT_LABEL_SHADOW_PAINT = Color.lightGray;    /**      * The default maximum value plotted - forces the plot to evaluate     *  the maximum from the data passed in     */    public static final double DEFAULT_MAX_VALUE = -1.0;    /** The head radius as a percentage of the available drawing area. */    protected double headPercent;    /** The space left around the outside of the plot as a percentage. */    private double interiorGap;    /** The gap between the labels and the axes as a %age of the radius. */    private double axisLabelGap;    /** The dataset. */    private CategoryDataset dataset;    /** The maximum value we are plotting against on each category axis */    private double maxValue;      /**      * The data extract order (BY_ROW or BY_COLUMN). This denotes whether     * the data series are stored in rows (in which case the category names are     * derived from the column keys) or in columns (in which case the category     * names are derived from the row keys).     */    private TableOrder dataExtractOrder;    /** The starting angle. */    private double startAngle;    /** The direction for drawing the radar axis & plots. */    private Rotation direction;    /** The legend item shape. */    private transient Shape legendItemShape;    /** The paint for ALL series (overrides list). */    private transient Paint seriesPaint;    /** The series paint list. */    private PaintList seriesPaintList;    /** The base series paint (fallback). */    private transient Paint baseSeriesPaint;    /** The outline paint for ALL series (overrides list). */    private transient Paint seriesOutlinePaint;    /** The series outline paint list. */    private PaintList seriesOutlinePaintList;    /** The base series outline paint (fallback). */    private transient Paint baseSeriesOutlinePaint;    /** The outline stroke for ALL series (overrides list). */    private transient Stroke seriesOutlineStroke;    /** The series outline stroke list. */    private StrokeList seriesOutlineStrokeList;    /** The base series outline stroke (fallback). */    private transient Stroke baseSeriesOutlineStroke;    /** The font used to display the category labels. */    private Font labelFont;    /** The color used to draw the category labels. */    private transient Paint labelPaint;        /** The label generator. */    private CategoryItemLabelGenerator labelGenerator;    /** controls if the web polygons are filled or not */    private boolean webFilled = true;      /**     * Creates a new radar plot with default attributes.     *      * @param dataset  the dataset.     */    public SpiderWebPlot(CategoryDataset dataset) {        super();        this.dataset = dataset;            if (dataset != null) {            dataset.addChangeListener(this);        }        this.dataExtractOrder = TableOrder.BY_ROW;        this.headPercent = DEFAULT_HEAD;        this.axisLabelGap = DEFAULT_AXIS_LABEL_GAP;        this.interiorGap = DEFAULT_INTERIOR_GAP;        this.startAngle = DEFAULT_START_ANGLE;        this.direction = Rotation.CLOCKWISE;        this.maxValue = DEFAULT_MAX_VALUE;        this.seriesPaint = null;        this.seriesPaintList = new PaintList();        this.baseSeriesPaint = null;        this.seriesOutlinePaint = null;        this.seriesOutlinePaintList = new PaintList();        this.baseSeriesOutlinePaint = DEFAULT_OUTLINE_PAINT;        this.seriesOutlineStroke = null;        this.seriesOutlineStrokeList = new StrokeList();        this.baseSeriesOutlineStroke = DEFAULT_OUTLINE_STROKE;        this.labelFont = DEFAULT_LABEL_FONT;        this.labelPaint = DEFAULT_LABEL_PAINT;        this.labelGenerator = new StandardCategoryItemLabelGenerator();                this.legendItemShape = DEFAULT_LEGEND_ITEM_CIRCLE;    }    /**     * Creates a new radar plot overriding the data extraction order.     *      * @param data  the data.     * @param type  controls how radar data is extracted (BY_ROW or BY_COLUMN).     */    public SpiderWebPlot(CategoryDataset data, TableOrder type) {        this(data);        this.dataExtractOrder = type;    }    /**     * Returns a short string describing the type of plot.     *      * @return The plot type.     */    public String getPlotType() {        // return localizationResources.getString("Radar_Plot");        return ("Radar Plot");    }        /**     * Method to determine if the web chart is to be filled.     *      * @return A boolean.     */    public boolean isWebFilled() {        return this.webFilled;    }    /**     * Sets the webFilled flag and sends a     * {@link PlotChangeEvent} to all registered listeners.     *      * @param flag  the flag.     */    public void setWebFilled(boolean flag) {        this.webFilled = flag;        notifyListeners(new PlotChangeEvent(this));    }      /**     * Returns the data extract order (by row or by column).     *      * @return The data extract order (never <code>null</code>).     */    public TableOrder getDataExtractOrder() {        return this.dataExtractOrder;    }    /**     * Sets the data extract order (by row or by column) and sends a     * {@link PlotChangeEvent}to all registered listeners.     *      * @param order the order (<code>null</code> not permitted).     */    public void setDataExtractOrder(TableOrder order) {        if (order == null) {            throw new IllegalArgumentException("Null 'order' argument");        }        this.dataExtractOrder = order;        notifyListeners(new PlotChangeEvent(this));    }    /**     * Returns the start angle for the first radar axis.     * <BR>     * This is measured in degrees starting from 3 o'clock (Java Arc2D default)     * and measuring anti-clockwise.     *      * @return The start angle.     */    public double getStartAngle() {        return this.startAngle;    }    /**     * Sets the starting angle and sends a {@link PlotChangeEvent} to all     * registered listeners.     * <P>     * The initial default value is 90 degrees, which corresponds to 12 o'clock.     * A value of zero corresponds to 3 o'clock... this is the encoding used by     * Java's Arc2D class.     *      * @param angle  the angle (in degrees).     */    public void setStartAngle(double angle) {        this.startAngle = angle;        notifyListeners(new PlotChangeEvent(this));    }    /**     * Returns the maximum value any category axis can take.     *      * @return The maximum value.     */    public double getMaxValue() {        return this.maxValue;    }    /**     * Sets the maximum value any category axis can take and sends      * a {@link PlotChangeEvent} to all registered listeners.     *      * @param value  the maximum value.     */    public void setMaxValue(double value) {        this.maxValue = value;        notifyListeners(new PlotChangeEvent(this));    }    /**     * Returns the direction in which the radar axes are drawn     * (clockwise or anti-clockwise).     *      * @return The direction (never <code>null</code>).     */    public Rotation getDirection() {        return this.direction;    }    /**     * Sets the direction in which the radar axes are drawn and sends a     * {@link PlotChangeEvent} to all registered listeners.     *      * @param direction  the direction (<code>null</code> not permitted).     */    public void setDirection(Rotation direction) {        if (direction == null) {            throw new IllegalArgumentException("Null 'direction' argument.");        }        this.direction = direction;

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?