categoryplot.java

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

JAVA
1,964
字号
     * @param dataset  the dataset (<code>null</code> permitted).     *      * @return The renderer (possibly <code>null</code>).     */    public CategoryItemRenderer getRendererForDataset(CategoryDataset dataset) {        CategoryItemRenderer result = null;        for (int i = 0; i < this.datasets.size(); i++) {            if (this.datasets.get(i) == dataset) {                result = (CategoryItemRenderer) this.renderers.get(i);                   break;            }        }        return result;    }        /**     * Returns the index of the specified renderer, or <code>-1</code> if the     * renderer is not assigned to this plot.     *      * @param renderer  the renderer (<code>null</code> permitted).     *      * @return The renderer index.     */    public int getIndexOf(CategoryItemRenderer renderer) {        return this.renderers.indexOf(renderer);    }    /**     * Returns the dataset rendering order.     *     * @return The order (never <code>null</code>).     */    public DatasetRenderingOrder getDatasetRenderingOrder() {        return this.renderingOrder;    }    /**     * Sets the rendering order and sends a {@link PlotChangeEvent} to all      * registered listeners.  By default, the plot renders the primary dataset      * last (so that the primary dataset overlays the secondary datasets).  You      * can reverse this if you want to.     *     * @param order  the rendering order (<code>null</code> not permitted).     */    public void setDatasetRenderingOrder(DatasetRenderingOrder order) {        if (order == null) {            throw new IllegalArgumentException("Null 'order' argument.");           }        this.renderingOrder = order;        notifyListeners(new PlotChangeEvent(this));    }    /**     * Returns the order in which the columns are rendered.     *      * @return The order.     */        public SortOrder getColumnRenderingOrder() {        return this.columnRenderingOrder;    }        /**     * Sets the order in which the columns should be rendered.     *      * @param order  the order.     */    public void setColumnRenderingOrder(SortOrder order) {        this.columnRenderingOrder = order;    }        /**     * Returns the order in which the rows should be rendered.     *      * @return The order (never <code>null</code>).     */    public SortOrder getRowRenderingOrder() {        return this.rowRenderingOrder;    }    /**     * Sets the order in which the rows should be rendered.     *      * @param order  the order (<code>null</code> not allowed).     */    public void setRowRenderingOrder(SortOrder order) {        if (order == null) {            throw new IllegalArgumentException("Null 'order' argument.");        }        this.rowRenderingOrder = order;    }        /**     * Returns the flag that controls whether the domain grid-lines are visible.     *     * @return The <code>true</code> or <code>false</code>.     */    public boolean isDomainGridlinesVisible() {        return this.domainGridlinesVisible;    }    /**     * Sets the flag that controls whether or not grid-lines are drawn against      * the domain axis.     * <p>     * If the flag value changes, a {@link PlotChangeEvent} is sent to all      * registered listeners.     *     * @param visible  the new value of the flag.     */    public void setDomainGridlinesVisible(boolean visible) {        if (this.domainGridlinesVisible != visible) {            this.domainGridlinesVisible = visible;            notifyListeners(new PlotChangeEvent(this));        }    }    /**     * Returns the position used for the domain gridlines.     *      * @return The gridline position.     */    public CategoryAnchor getDomainGridlinePosition() {        return this.domainGridlinePosition;    }    /**     * Sets the position used for the domain gridlines.     *      * @param position  the position.     */    public void setDomainGridlinePosition(CategoryAnchor position) {        this.domainGridlinePosition = position;        notifyListeners(new PlotChangeEvent(this));    }    /**     * Returns the stroke used to draw grid-lines against the domain axis.     *     * @return The stroke.     */    public Stroke getDomainGridlineStroke() {        return this.domainGridlineStroke;    }    /**     * Sets the stroke used to draw grid-lines against the domain axis.  A      * {@link PlotChangeEvent} is sent to all registered listeners.     *     * @param stroke  the stroke.     */    public void setDomainGridlineStroke(Stroke stroke) {        this.domainGridlineStroke = stroke;        notifyListeners(new PlotChangeEvent(this));    }    /**     * Returns the paint used to draw grid-lines against the domain axis.     *     * @return The paint.     */    public Paint getDomainGridlinePaint() {        return this.domainGridlinePaint;    }    /**     * Sets the paint used to draw the grid-lines (if any) against the domain      * axis.  A {@link PlotChangeEvent} is sent to all registered listeners.     *     * @param paint  the paint.     */    public void setDomainGridlinePaint(Paint paint) {        this.domainGridlinePaint = paint;        notifyListeners(new PlotChangeEvent(this));    }    /**     * Returns the flag that controls whether the range grid-lines are visible.     *     * @return The flag.     */    public boolean isRangeGridlinesVisible() {        return this.rangeGridlinesVisible;    }    /**     * Sets the flag that controls whether or not grid-lines are drawn against      * the range axis.  If the flag changes value, a {@link PlotChangeEvent} is      * sent to all registered listeners.     *     * @param visible  the new value of the flag.     */    public void setRangeGridlinesVisible(boolean visible) {        if (this.rangeGridlinesVisible != visible) {            this.rangeGridlinesVisible = visible;            notifyListeners(new PlotChangeEvent(this));        }    }    /**     * Returns the stroke used to draw the grid-lines against the range axis.     *     * @return The stroke.     */    public Stroke getRangeGridlineStroke() {        return this.rangeGridlineStroke;    }    /**     * Sets the stroke used to draw the grid-lines against the range axis.     * A {@link PlotChangeEvent} is sent to all registered listeners.     *     * @param stroke  the stroke.     */    public void setRangeGridlineStroke(Stroke stroke) {        this.rangeGridlineStroke = stroke;        notifyListeners(new PlotChangeEvent(this));    }    /**     * Returns the paint used to draw the grid-lines against the range axis.     *     * @return The paint.     */    public Paint getRangeGridlinePaint() {        return this.rangeGridlinePaint;    }    /**     * Sets the paint used to draw the grid lines against the range axis.     * A {@link PlotChangeEvent} is sent to all registered listeners.     *     * @param paint  the paint.     */    public void setRangeGridlinePaint(Paint paint) {        this.rangeGridlinePaint = paint;        notifyListeners(new PlotChangeEvent(this));    }        /**     * Returns the fixed legend items, if any.     *      * @return The legend items (possibly <code>null</code>).     */    public LegendItemCollection getFixedLegendItems() {        return this.fixedLegendItems;       }    /**     * Sets the fixed legend items for the plot.  Leave this set to      * <code>null</code> if you prefer the legend items to be created      * automatically.     *      * @param items  the legend items (<code>null</code> permitted).     */    public void setFixedLegendItems(LegendItemCollection items) {        this.fixedLegendItems = items;        notifyListeners(new PlotChangeEvent(this));    }        /**     * Returns the legend items for the plot.  By default, this method creates      * a legend item for each series in each of the datasets.  You can change      * this behaviour by overriding this method.     *     * @return The legend items.     */    public LegendItemCollection getLegendItems() {        LegendItemCollection result = this.fixedLegendItems;        if (result == null) {            result = new LegendItemCollection();            // get the legend items for the datasets...            int count = this.datasets.size();            for (int datasetIndex = 0; datasetIndex < count; datasetIndex++) {                CategoryDataset dataset = getDataset(datasetIndex);                if (dataset != null) {                    CategoryItemRenderer renderer = getRenderer(datasetIndex);                    if (renderer != null) {                        int seriesCount = dataset.getRowCount();                        for (int i = 0; i < seriesCount; i++) {                            LegendItem item = renderer.getLegendItem(                                datasetIndex, i                            );                            if (item != null) {                                result.add(item);                            }                        }                    }                }            }        }        return result;    }    /**     * Handles a 'click' on the plot by updating the anchor value.     *     * @param x  x-coordinate of the click (in Java2D space).     * @param y  y-coordinate of the click (in Java2D space).     * @param info  information about the plot's dimensions.     *     */    public void handleClick(int x, int y, PlotRenderingInfo info) {        Rectangle2D dataArea = info.getDataArea();        if (dataArea.contains(x, y)) {            // set the anchor value for the range axis...            double java2D = 0.0;            if (this.orientation == PlotOrientation.HORIZONTAL) {                java2D = x;            }            else if (this.orientation == PlotOrientation.VERTICAL) {                java2D = y;            }            RectangleEdge edge = Plot.resolveRangeAxisLocation(                getRangeAxisLocation(), this.orientation            );            double value = getRangeAxis().java2DToValue(                java2D, info.getDataArea(), edge            );            setAnchorValue(value);            setRangeCrosshairValue(value);        }    }    /**     * Zooms (in or out) on the plot's value axis.     * <p>     * If the value 0.0 is passed in as the zoom percent, the auto-range     * calculation for the axis is restored (which sets the range to include     * the minimum and maximum data values, thus displaying all the data).     *     * @param percent  the zoom amount.     */    public void zoom(double percent) {        if (percent > 0.0) {            double range = getRangeAxis().getRange().getLength();            double scaledRange = range * percent;            getRangeAxis().setRange(                this.anchorValue - scaledRange / 2.0,                this.anchorValue + scaledRange / 2.0            );        }        else {            getRangeAxis().setAutoRange(true);        }    }    /**     * Receives notification of a change to the plot's dataset.     * <P>     * The range axis bounds will be recalculated if necessary.     *     * @param event  information about the event (not used here).     */    public void datasetChanged(DatasetChangeEvent event) {        int count = this.rangeAxes.size();        for (int axisIndex = 0; axisIndex < count; axisIndex++) {            ValueAxis yAxis = getRangeAxis(axisIndex);            if (yAxis != null) {                yAxis.configure();            }        }        if (getParent() != null) {            getParent().datasetChanged(event);        }        else {            PlotChangeEvent e = new PlotChangeEvent(this);            e.setType(ChartChangeEventType.DATASET_UPDATED);            notifyListeners(e);        }    }    /**     * Receives notification of a renderer change event.     *     * @param event  the event.     */    public void rendererChanged(RendererChangeEvent event) {        Plot parent = getParent();        if (parent != null) {            if (parent instanceof RendererChangeListener) {                RendererChangeListener rcl = (RendererChangeListener) parent;                rcl.rendererChanged(event);            }            else {                // this should never happen with the existing code, but throw                 // an exception in case future changes make it possible...                throw new RuntimeException(

⌨️ 快捷键说明

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