schmitzm.jfree
Class JFreeChartUtil

java.lang.Object
  extended by schmitzm.jfree.JFreeChartUtil

public class JFreeChartUtil
extends Object

In dieser Klasse sind Hilfsmethoden fuer JFreeChart hinterlegt.

Version:
1.0
Author:
Martin Schmitz (University of Bonn/Germany)

Field Summary
static ChartStyleXMLFactory<ChartStyle> CHART_STYLE_FACTORY
          Instance of ChartStyleXMLFactory.
static Double DEFAULT_CENTRATION_BOUNDARY_PCT
          Default percentage, an (axis) range is extended with on centering to avoid points directly on the plot border.
static ResourceProvider RESOURCE
          ResourceProvider, der die Lokalisation fuer GUI-Komponenten zur Verfuegung stellt.
 
Constructor Summary
JFreeChartUtil()
           
 
Method Summary
static void addRegressionLineToPlot(XYPlot plot, XYDataset regressionData, Color lineColor)
          Adds a line plot for regression data to a plot.
static void applyDatasetProperties(Dataset dataset, Dataset sample)
          Applies general dataset properties to a Dataset.
static Range centerRange(Range range, Double boundaryPct)
          Returns a new centered Range defined as [-maxAbs; maxAbs] of a given Range.
static CategoryItemRenderer createCategoryRenderer(BasicChartStyle style)
          Creates a CategoryItemRenderer for the given stepped and stacked properties.
static CategoryItemRenderer createCategoryRenderer(ChartType type, boolean stepped, boolean stacked)
          Creates a CategoryItemRenderer for the given stepped and stacked properties.
static JFreeChart createRegressionChart(XYDataset dataset, String title, String xAxisTitle, String yAxisTitle, boolean regressionLine)
          Creates a JFreeChart which shows a point for each data item and a the appropriate regression line.
static XYDataset createRegressionLineDataset(XYDataset dataset, int series, String seriesKey, double startX, double endX, int sampleCount)
          Creates sample data for a regression line of an XYDataset.
static XYDataset createRegressionLineDataset(XYSeriesCollection dataset, int series, String seriesKey, int sampleCount)
          Creates sample data for a regression line of an XYDataset.
static XYItemRenderer createXYRenderer(BasicChartStyle style)
          Creates a XYItemRenderer for the given stepped and stacked properties.
static XYItemRenderer createXYRenderer(ChartType type, boolean stepped, boolean stacked)
          Creates a XYItemRenderer for the given stepped and stacked properties.
static void fireChangeEvent(AbstractRenderer renderer)
          Fires a change event to all RendererChangeListener connected to the renderer.
static void fireChangeEvent(Plot plot)
          Fires a change event to all PlotChangeListener connected to the plot.
static double getAbsRange(Range range, Double boundaryPct)
          Returns the maximum extend of a Range including a given boundary.
static Dataset getDatasetForRenderer(Plot plot, Object renderer)
          Returns the (first) dataset of a Plot which is rendererd by a renderer.
static Object getRendererForDataset(Plot plot, int i)
          Returns the renderer for the i-th dataset of a plot.
static DatasetSelectionModel<?,?,?> getSelectionModelForDataset(Plot plot, Dataset dataset)
          Searchs the renderers of a plot for SelectionRenderer for a Dataset and returns its DatasetSelectionModel.
static Map<Integer,DatasetSelectionModel<?,?,?>> getSelectionModels(Plot plot)
          Searchs the renderers of a plot for all SelectionRenderer and returns their DatasetSelectionModels.
static Map<Integer,SelectionRenderer<?>> getSelectionRenderer(Plot plot)
          Returns all SelectionRenderer for a Plot.
static SelectionRenderer<?> getSelectionRendererForDataset(Plot plot, Dataset dataset)
          Searchs the renderers of a plot for SelectionRenderer for a Dataset.
static String R(String key, Object... values)
          Convenience method to access the ResourceProvider.
static void setLegendVisible(JFreeChart chart, boolean visible)
          Sets all chart legends (in)visible.
static void zoomAxisToFullExtend(ValueAxis axis, Double boundaryPct, boolean symmetric)
          Centers a gives Axis around 0 (if normalized) or around it's center.
static void zoomPlotToFullExtend(Plot plot, Double boundaryPct, boolean symetric)
          Centers a gives Plot.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_CENTRATION_BOUNDARY_PCT

public static final Double DEFAULT_CENTRATION_BOUNDARY_PCT
Default percentage, an (axis) range is extended with on centering to avoid points directly on the plot border.


RESOURCE

public static ResourceProvider RESOURCE
ResourceProvider, der die Lokalisation fuer GUI-Komponenten zur Verfuegung stellt. Diese sind in properties-Datein unter schmitzm.jfree.resource.locales.JFreeResourceBundle_XXX.properties hinterlegt.


CHART_STYLE_FACTORY

public static final ChartStyleXMLFactory<ChartStyle> CHART_STYLE_FACTORY
Instance of ChartStyleXMLFactory.

Constructor Detail

JFreeChartUtil

public JFreeChartUtil()
Method Detail

R

public static String R(String key,
                       Object... values)
Convenience method to access the ResourceProvider.


setLegendVisible

public static void setLegendVisible(JFreeChart chart,
                                    boolean visible)
Sets all chart legends (in)visible.

Parameters:
chart - a chart to apply
visible - indicates the visible property

fireChangeEvent

public static void fireChangeEvent(Plot plot)
Fires a change event to all PlotChangeListener connected to the plot.

Parameters:
plot - a plot

fireChangeEvent

public static void fireChangeEvent(AbstractRenderer renderer)
Fires a change event to all RendererChangeListener connected to the renderer.

Parameters:
renderer - a renderer

getAbsRange

public static double getAbsRange(Range range,
                                 Double boundaryPct)
Returns the maximum extend of a Range including a given boundary.

Parameters:
range - a Range
boundaryPct - extends the Range bound by percentage (if null is used).
Returns:
a value >= 0

centerRange

public static Range centerRange(Range range,
                                Double boundaryPct)
Returns a new centered Range defined as [-maxAbs; maxAbs] of a given Range.

Parameters:
range - the Range to center
boundaryPct - extends the range's absolute maximum by percentage (if null is used).
Returns:
a new Range object

zoomAxisToFullExtend

public static void zoomAxisToFullExtend(ValueAxis axis,
                                        Double boundaryPct,
                                        boolean symmetric)
Centers a gives Axis around 0 (if normalized) or around it's center.

Parameters:
axis - the Axis to center
boundaryPct - extends the axis range's absolute maximum by percentage (if null is used).
symmetric - If true the axis is centered symetrically

zoomPlotToFullExtend

public static void zoomPlotToFullExtend(Plot plot,
                                        Double boundaryPct,
                                        boolean symetric)
Centers a gives Plot. For CategoryPlot only the range axis is centered.

Parameters:
axis - the Plot to center
boundaryPct - percentage boundary the absolute maximum is extended with
symetric - If true the axis is centered symmetrically around it medium.

createXYRenderer

public static XYItemRenderer createXYRenderer(BasicChartStyle style)
Creates a XYItemRenderer for the given stepped and stacked properties.

Parameters:
type - chart type
stepped - stepped property
stacked - stacked property

createXYRenderer

public static XYItemRenderer createXYRenderer(ChartType type,
                                              boolean stepped,
                                              boolean stacked)
Creates a XYItemRenderer for the given stepped and stacked properties.

Parameters:
type - chart type
stepped - stepped property
stacked - stacked property

createCategoryRenderer

public static CategoryItemRenderer createCategoryRenderer(BasicChartStyle style)
Creates a CategoryItemRenderer for the given stepped and stacked properties.

Parameters:
type - chart type
stepped - stepped property
stacked - stacked property

createCategoryRenderer

public static CategoryItemRenderer createCategoryRenderer(ChartType type,
                                                          boolean stepped,
                                                          boolean stacked)
Creates a CategoryItemRenderer for the given stepped and stacked properties.

Parameters:
type - chart type
stepped - stepped property
stacked - stacked property

getRendererForDataset

public static Object getRendererForDataset(Plot plot,
                                           int i)
Returns the renderer for the i-th dataset of a plot.

Parameters:
plot - a plot
index - the dataset index
Returns:
the primary renderer if no specific renderer is set for dataset i

getSelectionRendererForDataset

public static SelectionRenderer<?> getSelectionRendererForDataset(Plot plot,
                                                                  Dataset dataset)
Searchs the renderers of a plot for SelectionRenderer for a Dataset.

Parameters:
plot - the plot to check for renderer
dataset - the dataset a SelectionRenderer is searched for
Returns:
null if there is no SelectionRenderer defined for the dataset

getSelectionModelForDataset

public static DatasetSelectionModel<?,?,?> getSelectionModelForDataset(Plot plot,
                                                                       Dataset dataset)
Searchs the renderers of a plot for SelectionRenderer for a Dataset and returns its DatasetSelectionModel.

Parameters:
plot - the plot to check for renderer
dataset - the dataset a SelectionRenderer is searched for
Returns:
null if there is no SelectionRenderer defined for the dataset

getSelectionRenderer

public static Map<Integer,SelectionRenderer<?>> getSelectionRenderer(Plot plot)
Returns all SelectionRenderer for a Plot.

Parameters:
plot - the plot to check for renderer
Returns:
never null

getSelectionModels

public static Map<Integer,DatasetSelectionModel<?,?,?>> getSelectionModels(Plot plot)
Searchs the renderers of a plot for all SelectionRenderer and returns their DatasetSelectionModels.

Parameters:
plot - the plot to check for renderer
Returns:
never null

getDatasetForRenderer

public static Dataset getDatasetForRenderer(Plot plot,
                                            Object renderer)
Returns the (first) dataset of a Plot which is rendererd by a renderer.

Parameters:
plot - the plot which holds the datasets and renderer
renderer - the renderer a dataset is seached for
Returns:
null if there is no dataset which is rendered by the given renderer

applyDatasetProperties

public static void applyDatasetProperties(Dataset dataset,
                                          Dataset sample)
Applies general dataset properties to a Dataset.

Parameters:
dataset - dataset the properties are applied to
sample - dataset the properties are taken from

createRegressionChart

public static JFreeChart createRegressionChart(XYDataset dataset,
                                               String title,
                                               String xAxisTitle,
                                               String yAxisTitle,
                                               boolean regressionLine)
Creates a JFreeChart which shows a point for each data item and a the appropriate regression line.

Parameters:
dataset - the data
title - title for the chart
xAxisTitle - title for the X-Axis
yAxisTitle - title for the Y-Axis
regressionLine - indicates whether the regression line is shown

createRegressionLineDataset

public static XYDataset createRegressionLineDataset(XYSeriesCollection dataset,
                                                    int series,
                                                    String seriesKey,
                                                    int sampleCount)
Creates sample data for a regression line of an XYDataset.

Parameters:
dataset - data the regression line is created for
series - series of dataset the regression line is created for
seriesKey - the key for the created dataset
sampleCnt - count of created samples

createRegressionLineDataset

public static XYDataset createRegressionLineDataset(XYDataset dataset,
                                                    int series,
                                                    String seriesKey,
                                                    double startX,
                                                    double endX,
                                                    int sampleCount)
Creates sample data for a regression line of an XYDataset.

Parameters:
dataset - data the regression line is created for
series - series of dataset the regression line is created for
seriesKey - the key for the created dataset
startX - the first value the sample data is created for
endX - the last value the sample data is created for
sampleCnt - count of created samples
Returns:
null if the regression data could not be created (because of an error

addRegressionLineToPlot

public static void addRegressionLineToPlot(XYPlot plot,
                                           XYDataset regressionData,
                                           Color lineColor)
Adds a line plot for regression data to a plot.

Parameters:
plot - the plot the line is added to (at the end)
regressionData - the regression data
lineColor - the color for the regression line