com.approximatrix.charting.model
Class ObjectChartDataModel

java.lang.Object
  extended by com.approximatrix.charting.model.AbstractChartDataModel
      extended by com.approximatrix.charting.model.ObjectChartDataModel
All Implemented Interfaces:
ChartDataModel

public class ObjectChartDataModel
extends AbstractChartDataModel

The ObjectChartDataModel implements a ChartDataModel for Charts, which have e.g. String values on the x-axis. This is especially useful for Barcharts and also for Piecharts, although those don't exactly have an x-axis.

Author:
mueller armstrong

Field Summary
protected  java.lang.Object[] columns
          The x-axis values.
protected  ChartDataModelConstraints constraints1
          The constraints for the first and second y-axes.
protected  ChartDataModelConstraints constraints2
          The constraints for the first and second y-axes.
protected  DataSet[] data
          The data values.
protected  java.util.HashMap valuesbyaxis
          A HashMap containing the ordered data per axis.
 
Fields inherited from class com.approximatrix.charting.model.AbstractChartDataModel
autoscale, listener, maxcolumn, maxvalue, mincolumn, minvalue
 
Constructor Summary
ObjectChartDataModel()
          Creates a new empty DefaultChartDataModel.
ObjectChartDataModel(DataSet[] ds, java.lang.Object[] columns)
          Creates a new ObjectChartDataModel using the given array of DataSets, effectively enabling the creation of DataModels with differently sized DataSets.
ObjectChartDataModel(double[][] data, java.lang.Object[] columns, java.lang.String[] rows)
          Creates new ObjectChartDataModel.
ObjectChartDataModel(int[][] data, java.lang.Object[] columns, java.lang.String[] rows)
          Creates new ObjectChartDataModel.
ObjectChartDataModel(java.lang.Number[][] data, java.lang.Object[] columns, java.lang.String[] rows)
          Creates new ObjectChartDataModel with the default axis binding.
 
Method Summary
 int getAxisBinding(int set)
          Returns the axis to which a DataSet is attached
 ChartDataModelConstraints getChartDataModelConstraints(int axis)
          Returns a ChartDataModelConstraints Object for a given axis.
 java.lang.Object getColumnValueAt(int col)
          Returns a specific column value.
 java.lang.Object getColumnValueAt(int set, int col)
          Calls getColumnValueAt(int col).
 int getDataSetLength(int set)
          Returns the length of a certain dataset.
 java.lang.String getDataSetName(int set)
          Returns the title of the DataSet.
 int getDataSetNumber()
          Returns the total amount of datasets.
protected  double getFirstColumnValue()
          Is called by the ChartDataModelConstraints Object to compute the minimum column value.
protected  double getLastColumnValue()
          Is called by the ChartDataModelConstraints Object to compute the maximum column value.
protected  java.util.TreeSet getOrderedValues(int axis)
          Returns an ordered set of all data values for the specified axis.
 java.lang.Number getValueAt(int set, int index)
          Returns the Value in a specific dataset at a certain index.
 void setChartDataModelConstraints(int axis, ChartDataModelConstraints constraints)
          Sets the ChartDataModelConstraints object for the given axis binding.
 
Methods inherited from class com.approximatrix.charting.model.AbstractChartDataModel
addChartDataModelListener, equals, fireChartDataModelChangedEvent, getColumnClass, getManualMaximumColumnValue, getManualMaximumValue, getManualMaximumX, getManualMaximumY, getManualMinimumColumnValue, getManualMinimumValue, getManualMinimumX, getManualMinimumY, isAutoScale, isColumnNumeric, isManualScale, removeChartDataModelListener, setAutoScale, setAxisBinding, setManualScale, setMaximumColumnValue, setMaximumValue, setMaximumValueX, setMaximumValueY, setMinimumColumnValue, setMinimumValue, setMinimumValueX, setMinimumValueY, setValueAt
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

columns

protected java.lang.Object[] columns
The x-axis values.


data

protected DataSet[] data
The data values.


valuesbyaxis

protected java.util.HashMap valuesbyaxis
A HashMap containing the ordered data per axis.


constraints1

protected ChartDataModelConstraints constraints1
The constraints for the first and second y-axes.


constraints2

protected ChartDataModelConstraints constraints2
The constraints for the first and second y-axes.

Constructor Detail

ObjectChartDataModel

public ObjectChartDataModel()
Creates a new empty DefaultChartDataModel. Initializes all Objects and Arrays as empty ones.


ObjectChartDataModel

public ObjectChartDataModel(java.lang.Number[][] data,
                            java.lang.Object[] columns,
                            java.lang.String[] rows)
Creates new ObjectChartDataModel with the default axis binding.

Parameters:
data - the array of values. The first index specifies the datasets, the last one is the value index.
columns - the array of x-axis values. The length of the datasets and the length of the column should be equal and the columns should be ordered.
rows - the DataSet titles

ObjectChartDataModel

public ObjectChartDataModel(int[][] data,
                            java.lang.Object[] columns,
                            java.lang.String[] rows)
Creates new ObjectChartDataModel.

Parameters:
data - the array of values. The first index specifies the datasets, the last one is the value index.
columns - the array of x-axis values. The length of the datasets and the length of the column should be equal and the columns should be ordered.
rows - the DataSet titles

ObjectChartDataModel

public ObjectChartDataModel(double[][] data,
                            java.lang.Object[] columns,
                            java.lang.String[] rows)
Creates new ObjectChartDataModel.

Parameters:
data - the array of values. The first index specifies the datasets, the last one is the value index.
columns - the array of x-axis values. The length of the datasets and the length of the column should be equal and the columns should be ordered.
rows - the DataSet titles

ObjectChartDataModel

public ObjectChartDataModel(DataSet[] ds,
                            java.lang.Object[] columns)
Creates a new ObjectChartDataModel using the given array of DataSets, effectively enabling the creation of DataModels with differently sized DataSets. Internally, the DataSets are transformed into equally sized DataSets, where the missing data fields are filled with Double.NaN.

Parameters:
ds - the array of DataSets to be used.
columns - the array of column values. This needs to be supplied, because using Objects as x-axis values you need to have an ordered superset of all column values especially if different DataSets only contain some column values
Method Detail

getDataSetLength

public int getDataSetLength(int set)
Returns the length of a certain dataset.

Parameters:
set - the DataSet index
Returns:
the DataSet length

getDataSetNumber

public int getDataSetNumber()
Returns the total amount of datasets.

Returns:
the amount of DataSet

getDataSetName

public java.lang.String getDataSetName(int set)
Returns the title of the DataSet. This is the number of the DataSet per default.

Specified by:
getDataSetName in interface ChartDataModel
Overrides:
getDataSetName in class AbstractChartDataModel
Parameters:
set - the DataSet index
Returns:
the String title

getAxisBinding

public int getAxisBinding(int set)
Returns the axis to which a DataSet is attached

Specified by:
getAxisBinding in interface ChartDataModel
Overrides:
getAxisBinding in class AbstractChartDataModel
Parameters:
set - the DataSet index
Returns:
the axis constant

getValueAt

public java.lang.Number getValueAt(int set,
                                   int index)
Returns the Value in a specific dataset at a certain index.

Parameters:
set - the DataSet index
index - the value index
Returns:
the Number value

getChartDataModelConstraints

public ChartDataModelConstraints getChartDataModelConstraints(int axis)
Returns a ChartDataModelConstraints Object for a given axis. This way, there are different constraints for the first and for the second y-axis. If the model is empty, the maximum values are 1 and the minimum values are 0, thus enabling proper rendering.

Parameters:
axis - the axis constant
Returns:
the ChartDataModelConstraints for the defined y-axis

setChartDataModelConstraints

public void setChartDataModelConstraints(int axis,
                                         ChartDataModelConstraints constraints)
Sets the ChartDataModelConstraints object for the given axis binding.

Parameters:
axis - the Axis constant
constraints - the ChartDataModelConstraints object

getColumnValueAt

public java.lang.Object getColumnValueAt(int col)
Returns a specific column value.

Parameters:
col - the column index
Returns:
the column value or null if the column doesn't exist.

getColumnValueAt

public java.lang.Object getColumnValueAt(int set,
                                         int col)
Calls getColumnValueAt(int col).

Parameters:
col - the column index
set - the data set index
Returns:
the column value or null if the column doesn't exist.

getOrderedValues

protected java.util.TreeSet getOrderedValues(int axis)
Returns an ordered set of all data values for the specified axis. This is called by the ChartDataModelConstraints classes.

Specified by:
getOrderedValues in class AbstractChartDataModel

getFirstColumnValue

protected double getFirstColumnValue()
Is called by the ChartDataModelConstraints Object to compute the minimum column value.

Specified by:
getFirstColumnValue in class AbstractChartDataModel
Returns:
Returns 0.0.

getLastColumnValue

protected double getLastColumnValue()
Is called by the ChartDataModelConstraints Object to compute the maximum column value.

Specified by:
getLastColumnValue in class AbstractChartDataModel
Returns:
Returns columns.length.