hu.midori.kosmos.server.util
Class ChartUtils

java.lang.Object
  extended by hu.midori.kosmos.server.util.ChartUtils

public class ChartUtils
extends java.lang.Object

Utility methods for chart generation.

Version:
$Id$
Author:
Aron Gombas

Field Summary
static int MAX_ITEMS
          Max number of items in trimmed datasets.
protected static java.awt.Shape RECTANGLE_SHAPE
          Shape for the timeseries-charts.
protected static java.awt.Color TRANSPARENT_COLOR
          Transparent paint used as background in chart images.
 
Constructor Summary
protected ChartUtils()
          This class should never be instantiated.
 
Method Summary
static org.jfree.data.general.PieDataset collectionToPieDataset(java.util.Collection items)
          Returns the passed collection as untrimmed pie-dataset.
static org.jfree.data.general.PieDataset collectionToPieDataset(java.util.Collection items, int maxItems)
          Returns the passed collection of Map.Entry objects as pie-dataset (equivalent key-value pairs), optionally trimmed to a maximum number of items to prevent unreadably busy charts.
static java.util.List countMapToSortedList(java.util.Map map)
          Returns the list of the entries in the map sorted by their value (not by their key!) in descending order.
static org.jfree.chart.JFreeChart generateColorCodedPieChart(org.jfree.data.general.PieDataset dataset)
          Returns the color-coded pie-chart generated from the passed data.
static org.jfree.chart.JFreeChart generatePieChart(org.jfree.data.general.PieDataset dataset)
          Returns the pie-chart generated from the passed data.
static org.jfree.chart.JFreeChart generateTimeBarChart(org.jfree.data.time.TimeSeries dataset)
          Returns the time-barchart generated from the passed data.
static org.jfree.chart.JFreeChart generateTimeLineChart(org.jfree.data.time.TimeSeries dataset)
          Returns the time-chart generated from the passed data.
static void incrementCountMap(java.util.Map<java.lang.String,java.lang.Integer> map, java.lang.String key)
          Increments the counter (or starts that from 1 if not existing yet) in a String to Integer map.
static void writeChartAsPng(org.jfree.chart.JFreeChart chart, java.io.OutputStream out, int width, int height)
          Writes the given chart to the output-stream in PNG image format.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MAX_ITEMS

public static final int MAX_ITEMS
Max number of items in trimmed datasets.

See Also:
collectionToPieDataset(Collection, int), Constant Field Values

TRANSPARENT_COLOR

protected static final java.awt.Color TRANSPARENT_COLOR
Transparent paint used as background in chart images.


RECTANGLE_SHAPE

protected static final java.awt.Shape RECTANGLE_SHAPE
Shape for the timeseries-charts.

Constructor Detail

ChartUtils

protected ChartUtils()
This class should never be instantiated.

Method Detail

generatePieChart

public static org.jfree.chart.JFreeChart generatePieChart(org.jfree.data.general.PieDataset dataset)
Returns the pie-chart generated from the passed data.


generateColorCodedPieChart

public static org.jfree.chart.JFreeChart generateColorCodedPieChart(org.jfree.data.general.PieDataset dataset)
Returns the color-coded pie-chart generated from the passed data. The keys in the dataset are ColorCodedKey objects that specify both the pie section labels and the pie section colors.


generateTimeLineChart

public static org.jfree.chart.JFreeChart generateTimeLineChart(org.jfree.data.time.TimeSeries dataset)
Returns the time-chart generated from the passed data.


generateTimeBarChart

public static org.jfree.chart.JFreeChart generateTimeBarChart(org.jfree.data.time.TimeSeries dataset)
Returns the time-barchart generated from the passed data.


writeChartAsPng

public static void writeChartAsPng(org.jfree.chart.JFreeChart chart,
                                   java.io.OutputStream out,
                                   int width,
                                   int height)
                            throws java.io.IOException
Writes the given chart to the output-stream in PNG image format.

Throws:
java.io.IOException

collectionToPieDataset

public static org.jfree.data.general.PieDataset collectionToPieDataset(java.util.Collection items)
Returns the passed collection as untrimmed pie-dataset.

See Also:
collectionToPieDataset(Collection, int)

collectionToPieDataset

public static org.jfree.data.general.PieDataset collectionToPieDataset(java.util.Collection items,
                                                                       int maxItems)
Returns the passed collection of Map.Entry objects as pie-dataset (equivalent key-value pairs), optionally trimmed to a maximum number of items to prevent unreadably busy charts.

Parameters:
maxItems - the maximum number of items in the returned pie-dataset or -1 if trimming is not needed.

incrementCountMap

public static void incrementCountMap(java.util.Map<java.lang.String,java.lang.Integer> map,
                                     java.lang.String key)
Increments the counter (or starts that from 1 if not existing yet) in a String to Integer map.


countMapToSortedList

public static java.util.List countMapToSortedList(java.util.Map map)
Returns the list of the entries in the map sorted by their value (not by their key!) in descending order.