📄 xybardataset.java
字号:
/* ===========================================================
* JFreeChart : a free chart library for the Java(tm) platform
* ===========================================================
*
* (C) Copyright 2000-2004, 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.]
*
* -----------------
* XYBarDataset.java
* -----------------
* (C) Copyright 2004, by Object Refinery Limited and Contributors.
*
* Original Author: David Gilbert (for Object Refinery Limited);
* Contributor(s): -;
*
* $Id: XYBarDataset.java,v 1.1 2004/08/31 15:36:12 mungady Exp $
*
* Changes
* -------
* 02-Mar-2004 : Version 1 (DG);
* 05-May-2004 : Now extends AbstractIntervalXYDataset (DG);
* 15-Jul-2004 : Switched getX() with getXValue() and getY() with getYValue() (DG);
*
*/
package org.jfree.data.xy;
import org.jfree.data.general.DatasetChangeEvent;
import org.jfree.data.general.DatasetChangeListener;
/**
* A dataset wrapper class that converts a standard {@link XYDataset} into an
* {@link IntervalXYDataset} suitable for use in creating XY bar charts.
*/
public class XYBarDataset extends AbstractIntervalXYDataset
implements IntervalXYDataset, DatasetChangeListener {
/** The underlying dataset. */
private XYDataset underlying;
/** The bar width. */
private double barWidth;
/**
* Creates a new dataset.
*
* @param underlying the underlying dataset.
* @param barWidth the width of the bars.
*/
public XYBarDataset(XYDataset underlying, double barWidth) {
this.underlying = underlying;
this.underlying.addChangeListener(this);
this.barWidth = barWidth;
}
/**
* Returns the number of series in the dataset.
*
* @return The series count.
*/
public int getSeriesCount() {
return this.underlying.getSeriesCount();
}
/**
* Returns the name of a series.
*
* @param series the series index (zero-based).
*
* @return The series name.
*/
public String getSeriesName(int series) {
return this.underlying.getSeriesName(series);
}
/**
* Returns the number of items in a series.
*
* @param series the series index (zero-based).
*
* @return The item count.
*/
public int getItemCount(int series) {
return this.underlying.getItemCount(series);
}
/**
* Returns the x-value for an item within a series. The x-values may or may not be returned
* in ascending order, that is up to the class implementing the interface.
*
* @param series the series index (zero-based).
* @param item the item index (zero-based).
*
* @return The x-value.
*/
public Number getX(int series, int item) {
return this.underlying.getX(series, item);
}
/**
* Returns the y-value for an item within a series.
*
* @param series the series index (zero-based).
* @param item the item index (zero-based).
*
* @return The y-value (possibly <code>null</code>).
*/
public Number getY(int series, int item) {
return this.underlying.getY(series, item);
}
/**
* Returns the starting X value for the specified series and item.
*
* @param series the series index (zero-based).
* @param item the item index (zero-based).
*
* @return The value.
*/
public Number getStartX(int series, int item) {
Number result = null;
final Number xnum = this.underlying.getX(series, item);
if (xnum != null) {
result = new Double(xnum.doubleValue() - this.barWidth / 2.0);
}
return result;
}
/**
* Returns the ending X value for the specified series and item.
*
* @param series the series index (zero-based).
* @param item the item index (zero-based).
*
* @return The value.
*/
public Number getEndX(int series, int item) {
Number result = null;
final Number xnum = this.underlying.getX(series, item);
if (xnum != null) {
result = new Double(xnum.doubleValue() + this.barWidth / 2.0);
}
return result;
}
/**
* Returns the starting Y value for the specified series and item.
*
* @param series the series index (zero-based).
* @param item the item index (zero-based).
*
* @return The value.
*/
public Number getStartY(int series, int item) {
return this.underlying.getY(series, item);
}
/**
* Returns the ending Y value for the specified series and item.
*
* @param series the series index (zero-based).
* @param item the item index (zero-based).
*
* @return The value.
*/
public Number getEndY(int series, int item) {
return this.underlying.getY(series, item);
}
/**
* Receives notification of an dataset change event.
*
* @param event information about the event.
*/
public void datasetChanged(DatasetChangeEvent event) {
this.notifyListeners(event);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -