xysteparearenderer.java

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

JAVA
572
字号
/* =========================================================== * 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.] * * ----------------------- * XYStepAreaRenderer.java * ----------------------- * (C) Copyright 2003-2005, by Matthias Rose and Contributors. * * Original Author:  Matthias Rose (based on XYAreaRenderer.java); * Contributor(s):   David Gilbert (for Object Refinery Limited); * * $Id: XYStepAreaRenderer.java,v 1.7 2005/05/19 14:01:50 mungady Exp $ * * Changes: * -------- * 07-Oct-2003 : Version 1, contributed by Matthias Rose (DG); * 10-Feb-2004 : Added some getter and setter methods (DG); * 25-Feb-2004 : Replaced CrosshairInfo with CrosshairState.  Renamed  *               XYToolTipGenerator --> XYItemLabelGenerator (DG); * 15-Jul-2004 : Switched getX() with getXValue() and getY() with  *               getYValue() (DG); * 11-Nov-2004 : Now uses ShapeUtilities to translate shapes (DG); *  */package org.jfree.chart.renderer.xy;import java.awt.Graphics2D;import java.awt.Paint;import java.awt.Polygon;import java.awt.Shape;import java.awt.Stroke;import java.awt.geom.Rectangle2D;import java.io.Serializable;import org.jfree.chart.axis.ValueAxis;import org.jfree.chart.entity.EntityCollection;import org.jfree.chart.entity.XYItemEntity;import org.jfree.chart.event.RendererChangeEvent;import org.jfree.chart.labels.XYToolTipGenerator;import org.jfree.chart.plot.CrosshairState;import org.jfree.chart.plot.PlotOrientation;import org.jfree.chart.plot.PlotRenderingInfo;import org.jfree.chart.plot.XYPlot;import org.jfree.chart.urls.XYURLGenerator;import org.jfree.data.xy.XYDataset;import org.jfree.util.PublicCloneable;import org.jfree.util.ShapeUtilities;/** * A step chart renderer that fills the area between the step and the x-axis. */public class XYStepAreaRenderer extends AbstractXYItemRenderer                                 implements XYItemRenderer,                                            Cloneable,                                           PublicCloneable,                                           Serializable {    /** For serialization. */    private static final long serialVersionUID = -7311560779702649635L;        /** Useful constant for specifying the type of rendering (shapes only). */    public static final int SHAPES = 1;    /** Useful constant for specifying the type of rendering (area only). */    public static final int AREA = 2;    /**      * Useful constant for specifying the type of rendering (area and shapes).      */    public static final int AREA_AND_SHAPES = 3;    /** A flag indicating whether or not shapes are drawn at each XY point. */    private boolean plotShapes;    /** A flag that controls whether or not shapes are filled for ALL series. */    private boolean shapesFilled;    /** A flag indicating whether or not Area are drawn at each XY point. */    private boolean plotArea;    /** A flag that controls whether or not the outline is shown. */    private boolean showOutline;    /** Area of the complete series */    protected transient Polygon pArea = null;    /**      * The value on the range axis which defines the 'lower' border of the      * area.      */    private double rangeBase;    /**     * Constructs a new renderer.     */    public XYStepAreaRenderer() {        this(AREA);    }    /**     * Constructs a new renderer.     *     * @param type  the type of the renderer.     */    public XYStepAreaRenderer(int type) {        this(type, null, null);    }    /**     * Constructs a new renderer.     * <p>     * To specify the type of renderer, use one of the constants:     * AREA, SHAPES or AREA_AND_SHAPES.     *     * @param type  the type of renderer.     * @param toolTipGenerator  the tool tip generator to use      *                          (<code>null</code> permitted).     * @param urlGenerator  the URL generator (<code>null</code> permitted).     */    public XYStepAreaRenderer(int type,                              XYToolTipGenerator toolTipGenerator,                               XYURLGenerator urlGenerator) {        super();        setBaseToolTipGenerator(toolTipGenerator);        setURLGenerator(urlGenerator);        if (type == AREA) {            this.plotArea = true;        }        else if (type == SHAPES) {            this.plotShapes = true;        }        else if (type == AREA_AND_SHAPES) {            this.plotArea = true;            this.plotShapes = true;        }        this.showOutline = false;    }    /**     * Returns a flag that controls whether or not outlines of the areas are      * drawn.     *     * @return The flag.     */    public boolean isOutline() {        return this.showOutline;    }    /**     * Sets a flag that controls whether or not outlines of the areas are      * drawn, and sends a {@link RendererChangeEvent} to all registered      * listeners.     *     * @param show  the flag.     */    public void setOutline(boolean show) {        this.showOutline = show;        notifyListeners(new RendererChangeEvent(this));    }    /**     * Returns true if shapes are being plotted by the renderer.     *     * @return <code>true</code> if shapes are being plotted by the renderer.     */    public boolean getPlotShapes() {        return this.plotShapes;    }        /**     * Sets the flag that controls whether or not shapes are displayed for each      * data item.     *      * @param flag  the flag.     */    public void setPlotShapes(boolean flag) {        this.plotShapes = flag;        notifyListeners(new RendererChangeEvent(this));    }    /**     * Returns the flag that controls whether or not the shapes are filled.     *      * @return A boolean.     */    public boolean isShapesFilled() {        return this.shapesFilled;    }        /**     * Sets the 'shapes filled' for ALL series.     *     * @param filled  the flag.     */    public void setShapesFilled(boolean filled) {        this.shapesFilled = filled;        notifyListeners(new RendererChangeEvent(this));    }    /**     * Returns true if Area is being plotted by the renderer.     *     * @return <code>true</code> if Area is being plotted by the renderer.     */    public boolean getPlotArea() {        return this.plotArea;    }    /**     * Sets a flag that controls whether or not areas are drawn for each data      * item.     *      * @param flag  the flag.     */    public void setPlotArea(boolean flag) {        this.plotArea = flag;        notifyListeners(new RendererChangeEvent(this));    }        /**     * Returns the value on the range axis which defines the 'lower' border of     * the area.     *     * @return <code>double</code> the value on the range axis which defines      *         the 'lower' border of the area.     */    public double getRangeBase() {        return this.rangeBase;    }    /**     * Sets the value on the range axis which defines the default border of the      * area.  E.g. setRangeBase(Double.NEGATIVE_INFINITY) lets areas always      * reach the lower border of the plotArea.      *      * @param val  the value on the range axis which defines the default border     *             of the area.     */    public void setRangeBase(double val) {        this.rangeBase = val;        notifyListeners(new RendererChangeEvent(this));    }    /**     * Initialises the renderer.  Here we calculate the Java2D y-coordinate for     * zero, since all the bars have their bases fixed at zero.     *     * @param g2  the graphics device.     * @param dataArea  the area inside the axes.     * @param plot  the plot.     * @param data  the data.     * @param info  an optional info collection object to return data back to      *              the caller.     *     * @return The number of passes required by the renderer.     */    public XYItemRendererState initialise(Graphics2D g2,                                          Rectangle2D dataArea,                                          XYPlot plot,                                          XYDataset data,                                          PlotRenderingInfo info) {

⌨️ 快捷键说明

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