planetj.chart
Class ChartManager

java.lang.Object
  extended byplanetj.chart.ChartManager
All Implemented Interfaces:
IChartTypes

public class ChartManager
extends java.lang.Object
implements IChartTypes

Helper class that may be used to create charts and graphs from given RowCollections or Rows. Properties that are needed to create the charts are contained within a chart specification property group. This class uses JFreeChart behind the scenes.

See Also:
ChartSpecificationPG, IChartTypes

Field Summary
 
Fields inherited from interface planetj.chart.IChartTypes
HORIZONTAL_BAR, HORIZONTAL_BAR_3D, HORIZONTAL_BAR_3D_KEY, HORIZONTAL_BAR_KEY, LINE, LINE_KEY, PIE, PIE_3D, PIE_3D_KEY, PIE_KEY, UNKNOWN, VERTICAL_BAR, VERTICAL_BAR_3D, VERTICAL_BAR_3D_KEY, VERTICAL_BAR_KEY
 
Constructor Summary
protected ChartManager()
          ChartManager constructor.
 
Method Summary
protected  com.jrefinery.chart.JFreeChart createCategoryChart(int type, java.lang.String title, java.lang.String categoryAxisLabel, java.lang.String valueAxisLabel, com.jrefinery.data.CategoryDataset data, boolean legend, boolean tooltips, boolean urls)
          Creates a category chart with the given information.
 com.jrefinery.chart.JFreeChart createCategoryChart(RowCollection data, ChartSpecificationPG chartSpecs)
           
 com.jrefinery.chart.JFreeChart createChart(RowCollection data, ChartSpecificationPG chartSpecs)
          Convience method to create a JFreeChart given the data and chart specifications.
protected  java.lang.Number[][] extractCategoryData(RowCollection rc, java.util.List columnNames, boolean plotByRow)
          Extracts values from the given RowCollection to create a double array of Numeric values that can be used to create a category chart.
 com.jrefinery.data.CategoryDataset getCategoryDataset(RowCollection rc, ChartSpecificationPG chartSpecs)
          Creates a CategoryDataset using the given chart specifications and data.
 ChartSpecificationPG getChartSpecifications(java.lang.String chartId, RowCollection rc)
          Convience method to retrieve a chart specification property group that has the given chart id from a given RowCollection.
 int getType(java.lang.String type)
          Gets the type of chart to generate from the given chart abbreviation key.
static void setSingleton(ChartManager singleton)
          Allow subclasses to be set as the signleton instance to use.
static ChartManager singleton()
          Gets the singleton instance of ChartManager.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ChartManager

protected ChartManager()
ChartManager constructor.

Method Detail

createCategoryChart

protected com.jrefinery.chart.JFreeChart createCategoryChart(int type,
                                                             java.lang.String title,
                                                             java.lang.String categoryAxisLabel,
                                                             java.lang.String valueAxisLabel,
                                                             com.jrefinery.data.CategoryDataset data,
                                                             boolean legend,
                                                             boolean tooltips,
                                                             boolean urls)
                                                      throws ChartException
Creates a category chart with the given information.

Parameters:
type - type of category chart (see IChartTypes for supported types)
title - the chart title.
categoryAxisLabel - the label for the category axis.
valueAxisLabel - the label for the value axis.
data - the dataset for the chart.
legend - a flag specifying whether or not a legend is required.
tooltips - configure chart to generate tool tips?
urls - configure chart to generate URLs?
Returns:
an category chart.
Throws:
ChartException

createCategoryChart

public com.jrefinery.chart.JFreeChart createCategoryChart(RowCollection data,
                                                          ChartSpecificationPG chartSpecs)
                                                   throws CMException
Throws:
CMException

createChart

public com.jrefinery.chart.JFreeChart createChart(RowCollection data,
                                                  ChartSpecificationPG chartSpecs)
                                           throws CMException
Convience method to create a JFreeChart given the data and chart specifications.

Parameters:
data - RowCollection containing data to chart.
chartSpecs - properties on how the chart should be generated.
Returns:
JFreeChart generated from the given data and chart specifications.
Throws:
CMException

extractCategoryData

protected java.lang.Number[][] extractCategoryData(RowCollection rc,
                                                   java.util.List columnNames,
                                                   boolean plotByRow)
                                            throws CMException
Extracts values from the given RowCollection to create a double array of Numeric values that can be used to create a category chart.

Parameters:
rc - RowCollection containing values
columnNames - if plotting by row, these names will be the names of the columns for each category in the series; if not plotting by row, then these are the columns containing the series of values; if no columns are given, then by default all columns are used.
plotByRow - true if series values should be taken from the row; false if from columns
Throws:
CMException

getCategoryDataset

public com.jrefinery.data.CategoryDataset getCategoryDataset(RowCollection rc,
                                                             ChartSpecificationPG chartSpecs)
                                                      throws CMException
Creates a CategoryDataset using the given chart specifications and data.

Returns:
dataset that may be used to create a JFreechart.
Throws:
CMException

getChartSpecifications

public ChartSpecificationPG getChartSpecifications(java.lang.String chartId,
                                                   RowCollection rc)
Convience method to retrieve a chart specification property group that has the given chart id from a given RowCollection. If more than one property group contains that chart id, then the first one is returned.

Parameters:
chartId - id of the chart to retrieve chart specifications for.
rc - RowCollection containing chart property groups.

getType

public int getType(java.lang.String type)
Gets the type of chart to generate from the given chart abbreviation key.

Parameters:
type - chart abbreviation key used to get the chart type
Returns:
an int representing the type of chart to generate (see IChartTypes)

setSingleton

public static void setSingleton(ChartManager singleton)
Allow subclasses to be set as the signleton instance to use. The signleton instance is not synchronized, so this method must be invoked before the singleton is accessed.

Parameters:
singleton - helper class to use as the ChartManager.

singleton

public static ChartManager singleton()
Gets the singleton instance of ChartManager.

Returns:
singleton instance of the ChartManager.