2.17.2: 2011-06-17

net.sf.basedb.util.plot
Class HistogramPlot

java.lang.Object
  extended by net.sf.basedb.util.plot.HistogramPlot

public class HistogramPlot
extends Object

A simple plot utility for generating histogram plots without the need to delve deep into the JFreePlot package. Note! This class is experimental and it is likely that the implementation will change in the future.

Version:
2.0
Author:
Nicklas
Last modified
$Date: 2010-08-13 10:50:27 +0200 (Fri, 13 Aug 2010) $

Nested Class Summary
private static class HistogramPlot.HistogramBin
          Represents a single bin in a histogram.
private static class HistogramPlot.HistogramDataset
          An dataset implementation for histogram data that allows us to send data to JFreeChart the way we want.
private static class HistogramPlot.HistogramSeries
          Collects information about one histogram series.
private static class HistogramPlot.TempSeries
          Helper class for storing histogram data that needs to split into different annotations.
static class HistogramPlot.YAggregate
          Defines what to to plot on the y axis in a histogram plot.
 
Field Summary
private  JFreeChart chart
           
private  Range domainRange
           
private  HistogramPlot.HistogramDataset hilo
           
private  HistogramPlot.HistogramDataset histogram
           
private  XYPlot plot
           
private  Range rangeRange
           
 
Constructor Summary
HistogramPlot(String nameX, String nameY, XYItemRenderer renderer)
          Create a new HistogramPlot.
 
Method Summary
 void addData(SqlResultIterator data, Collection<PlotAnnotation> annotations, float binSize, HistogramPlot.YAggregate yAggregate, HistogramPlot.YAggregate hiloAggregate)
          Add data to the plot.
 void addData(SqlResultIterator data, String name, float binSize, HistogramPlot.YAggregate yAggregate, HistogramPlot.YAggregate hiloAggregate)
          Add data to the plot.
private  void adjustRanges()
          Auto-size of the x and y range doesn't seem to work, so we have to do it manually.
 JFreeChart getChart()
          Get the underlying JFreeChar object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

domainRange

private Range domainRange

rangeRange

private Range rangeRange

plot

private XYPlot plot

histogram

private HistogramPlot.HistogramDataset histogram

hilo

private HistogramPlot.HistogramDataset hilo

chart

private JFreeChart chart
Constructor Detail

HistogramPlot

public HistogramPlot(String nameX,
                     String nameY,
                     XYItemRenderer renderer)
Create a new HistogramPlot.

Parameters:
nameX - The label on the X-axis
nameY - The label on the Y-axis
renderer - The renderer to use or null for the default (XYBarRenderer)
Method Detail

addData

public void addData(SqlResultIterator data,
                    String name,
                    float binSize,
                    HistogramPlot.YAggregate yAggregate,
                    HistogramPlot.YAggregate hiloAggregate)
             throws SQLException
Add data to the plot. The SqlResultIterator should return the x value as a float in the first position, ie. data.getFloat(1) and, if used, the y value in the second position.

The y value is not used if the yAggregate parameter is HistogramPlot.YAggregate.COUNT.

Parameters:
data - The data to plot
name - The name of the data series
binSize - The size (= range on x-axis) of each histogram bin
yAggregate - What to plot on the y-axis
hiloAggregate - Optional parameter specifying if high/low values shold be drawn for each bin
Throws:
SQLException

adjustRanges

private void adjustRanges()
Auto-size of the x and y range doesn't seem to work, so we have to do it manually.


addData

public void addData(SqlResultIterator data,
                    Collection<PlotAnnotation> annotations,
                    float binSize,
                    HistogramPlot.YAggregate yAggregate,
                    HistogramPlot.YAggregate hiloAggregate)
             throws SQLException
Add data to the plot. The SqlResultIterator should return the annotation value in the first position, ie. data.getInt(1), the x value as a float in the second position, and, if used, the y value in the third position.

The y value is not used if the yAggregate parameter is HistogramPlot.YAggregate.COUNT.

Parameters:
data - The data to plot
annotations - Annotation information that maps each data spot to an annotation (see ScatterPlot.addData(SqlResultIterator, Collection)
binSize - The size (= range on x-axis) of each histogram bin
yAggregate - What to plot on the y-axis
hiloAggregate - Optional parameter specifying if high/low values shold be drawn for each bin
Throws:
SQLException

getChart

public JFreeChart getChart()
Get the underlying JFreeChar object. Use this method to polish up everything and save the image.


2.17.2: 2011-06-17