categoryplot.java
来自「JfreeChart 常用图表例子」· Java 代码 · 共 1,964 行 · 第 1/5 页
JAVA
1,964 行
setRangeAxis(index, axis, true); } /** * Sets a range axis and, if requested, sends a {@link PlotChangeEvent} to * all registered listeners. * * @param index the axis index. * @param axis the axis. * @param notify notify listeners? */ public void setRangeAxis(int index, ValueAxis axis, boolean notify) { ValueAxis existing = (ValueAxis) this.rangeAxes.get(index); if (existing != null) { existing.removeChangeListener(this); } if (axis != null) { axis.setPlot(this); } this.rangeAxes.set(index, axis); if (axis != null) { axis.configure(); axis.addChangeListener(this); } if (notify) { notifyListeners(new PlotChangeEvent(this)); } } /** * Sets the range axes for this plot and sends a {@link PlotChangeEvent} * to all registered listeners. * * @param axes the axes. */ public void setRangeAxes(ValueAxis[] axes) { for (int i = 0; i < axes.length; i++) { setRangeAxis(i, axes[i], false); } notifyListeners(new PlotChangeEvent(this)); } /** * Returns the range axis location. * * @return The location (never <code>null</code>). */ public AxisLocation getRangeAxisLocation() { return getRangeAxisLocation(0); } /** * Returns the location for a range axis. * * @param index the axis index. * * @return The location. */ public AxisLocation getRangeAxisLocation(int index) { AxisLocation result = null; if (index < this.rangeAxisLocations.size()) { result = (AxisLocation) this.rangeAxisLocations.get(index); } if (result == null) { result = AxisLocation.getOpposite(getRangeAxisLocation(0)); } return result; } /** * Sets the location of the range axis and sends a {@link PlotChangeEvent} * to all registered listeners. * * @param location the location (<code>null</code> not permitted). */ public void setRangeAxisLocation(AxisLocation location) { // defer argument checking... setRangeAxisLocation(location, true); } /** * Sets the location of the range axis and, if requested, sends a * {@link PlotChangeEvent} to all registered listeners. * * @param location the location (<code>null</code> not permitted). * @param notify notify listeners? */ public void setRangeAxisLocation(AxisLocation location, boolean notify) { setRangeAxisLocation(0, location, notify); } /** * Sets the location for a range axis and sends a {@link PlotChangeEvent} * to all registered listeners. * * @param index the axis index. * @param location the location. */ public void setRangeAxisLocation(int index, AxisLocation location) { setRangeAxisLocation(index, location, true); } /** * Sets the location for a range axis and sends a {@link PlotChangeEvent} * to all registered listeners. * * @param index the axis index. * @param location the location. * @param notify notify listeners? */ public void setRangeAxisLocation(int index, AxisLocation location, boolean notify) { // TODO: don't allow null for index = 0 this.rangeAxisLocations.set(index, location); if (notify) { notifyListeners(new PlotChangeEvent(this)); } } /** * Returns the edge where the primary range axis is located. * * @return The edge (never <code>null</code>). */ public RectangleEdge getRangeAxisEdge() { return getRangeAxisEdge(0); } /** * Returns the edge for a range axis. * * @param index the axis index. * * @return The edge. */ public RectangleEdge getRangeAxisEdge(int index) { AxisLocation location = getRangeAxisLocation(index); RectangleEdge result = Plot.resolveRangeAxisLocation( location, this.orientation ); if (result == null) { result = RectangleEdge.opposite(getRangeAxisEdge(0)); } return result; } /** * Clears the range axes from the plot and sends a {@link PlotChangeEvent} * to all registered listeners. */ public void clearRangeAxes() { for (int i = 0; i < this.rangeAxes.size(); i++) { ValueAxis axis = (ValueAxis) this.rangeAxes.get(i); if (axis != null) { axis.removeChangeListener(this); } } this.rangeAxes.clear(); notifyListeners(new PlotChangeEvent(this)); } /** * Configures the range axes. */ public void configureRangeAxes() { for (int i = 0; i < this.rangeAxes.size(); i++) { ValueAxis axis = (ValueAxis) this.rangeAxes.get(i); if (axis != null) { axis.configure(); } } } /** * Returns the primary dataset for the plot. * * @return The primary dataset (possibly <code>null</code>). */ public CategoryDataset getDataset() { return getDataset(0); } /** * Returns the dataset at the given index. * * @param index the dataset index. * * @return The dataset (possibly <code>null</code>). */ public CategoryDataset getDataset(int index) { CategoryDataset result = null; if (this.datasets.size() > index) { result = (CategoryDataset) this.datasets.get(index); } return result; } /** * Sets the dataset for the plot, replacing the existing dataset, if there * is one. This method also calls the * {@link #datasetChanged(DatasetChangeEvent)} method, which adjusts the * axis ranges if necessary and sends a {@link PlotChangeEvent} to all * registered listeners. * * @param dataset the dataset (<code>null</code> permitted). */ public void setDataset(CategoryDataset dataset) { setDataset(0, dataset); } /** * Sets a dataset for the plot. * * @param index the dataset index. * @param dataset the dataset (<code>null</code> permitted). */ public void setDataset(int index, CategoryDataset dataset) { CategoryDataset existing = (CategoryDataset) this.datasets.get(index); if (existing != null) { existing.removeChangeListener(this); } this.datasets.set(index, dataset); if (dataset != null) { dataset.addChangeListener(this); } // send a dataset change event to self... DatasetChangeEvent event = new DatasetChangeEvent(this, dataset); datasetChanged(event); } /** * Maps a dataset to a particular domain axis. * * @param index the dataset index (zero-based). * @param axisIndex the axis index (zero-based). */ public void mapDatasetToDomainAxis(int index, int axisIndex) { this.datasetToDomainAxisMap.set(index, new Integer(axisIndex)); // fake a dataset change event to update axes... datasetChanged(new DatasetChangeEvent(this, getDataset(index))); } /** * Returns the domain axis for a dataset. You can change the axis for a * dataset using the {@link #mapDatasetToDomainAxis(int, int)} method. * * @param index the dataset index. * * @return The domain axis. */ public CategoryAxis getDomainAxisForDataset(int index) { CategoryAxis result = getDomainAxis(); Integer axisIndex = (Integer) this.datasetToDomainAxisMap.get(index); if (axisIndex != null) { result = getDomainAxis(axisIndex.intValue()); } return result; } /** * Maps a dataset to a particular range axis. * * @param index the dataset index (zero-based). * @param axisIndex the axis index (zero-based). */ public void mapDatasetToRangeAxis(int index, int axisIndex) { this.datasetToRangeAxisMap.set(index, new Integer(axisIndex)); // fake a dataset change event to update axes... datasetChanged(new DatasetChangeEvent(this, getDataset(index))); } /** * Returns the range axis for a dataset. You can change the axis for a * dataset using the {@link #mapDatasetToRangeAxis(int, int)} method. * * @param index the dataset index. * * @return The range axis. */ public ValueAxis getRangeAxisForDataset(int index) { ValueAxis result = getRangeAxis(); Integer axisIndex = (Integer) this.datasetToRangeAxisMap.get(index); if (axisIndex != null) { result = getRangeAxis(axisIndex.intValue()); } return result; } /** * Returns a reference to the renderer for the plot. * * @return The renderer. */ public CategoryItemRenderer getRenderer() { return getRenderer(0); } /** * Returns the renderer at the given index. * * @param index the renderer index. * * @return The renderer (possibly <code>null</code>). */ public CategoryItemRenderer getRenderer(int index) { CategoryItemRenderer result = null; if (this.renderers.size() > index) { result = (CategoryItemRenderer) this.renderers.get(index); } return result; } /** * Sets the renderer at index 0 (sometimes referred to as the "primary" * renderer) and sends a {@link PlotChangeEvent} to all registered * listeners. * * @param renderer the renderer (<code>null</code> permitted. */ public void setRenderer(CategoryItemRenderer renderer) { setRenderer(0, renderer, true); } /** * Sets the renderer at index 0 (sometimes referred to as the "primary" * renderer) and, if requested, sends a {@link PlotChangeEvent} to all * registered listeners. * <p> * You can set the renderer to <code>null</code>, but this is not * recommended because: * <ul> * <li>no data will be displayed;</li> * <li>the plot background will not be painted;</li> * </ul> * * @param renderer the renderer (<code>null</code> permitted). * @param notify notify listeners? */ public void setRenderer(CategoryItemRenderer renderer, boolean notify) { setRenderer(0, renderer, notify); } /** * Sets the renderer at the specified index and sends a * {@link PlotChangeEvent} to all registered listeners. * * @param index the index. * @param renderer the renderer (<code>null</code> permitted). */ public void setRenderer(int index, CategoryItemRenderer renderer) { setRenderer(index, renderer, true); } /** * Sets a renderer. A {@link PlotChangeEvent} is sent to all registered * listeners. * * @param index the index. * @param renderer the renderer (<code>null</code> permitted). * @param notify notify listeners? */ public void setRenderer(int index, CategoryItemRenderer renderer, boolean notify) { // stop listening to the existing renderer... CategoryItemRenderer existing = (CategoryItemRenderer) this.renderers.get(index); if (existing != null) { existing.removeChangeListener(this); } // register the new renderer... this.renderers.set(index, renderer); if (renderer != null) { renderer.setPlot(this); renderer.addChangeListener(this); } configureDomainAxes(); configureRangeAxes(); if (notify) { notifyListeners(new PlotChangeEvent(this)); } } /** * Returns the renderer for the specified dataset. If the dataset doesn't * belong to the plot, this method will return <code>null</code>. *
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?