Class BarGraphDrawable
- java.lang.Object
-
- org.pentaho.reporting.libraries.libsparklines.BarGraphDrawable
-
public class BarGraphDrawable extends Object
A very fast and very simple bar-graph drawable. This code is based on the BarGraph class writen by Larry Ogrodnek but instead of producing a low-resolution image, this class writes the content into a Graphics2D context.- Author:
- Thomas Morgner
-
-
Constructor Summary
Constructors Constructor Description BarGraphDrawable()
Creates a default bargraph drawable with some sensible default colors and spacings.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
draw(Graphics2D g2, Rectangle2D drawArea)
Draws the bar-graph into the given Graphics2D context in the given area.Color
getBackground()
Returns the color for the background of the graph.Color
getColor()
Returns the main color for the bars.Number[]
getData()
Returns the numeric data for the drawable or null, if the drawable has no data.Color
getHighColor()
Returns the color for the highest bars.Color
getLastColor()
Returns the color for the last bar.int
getSpacing()
Returns the spacing between the bars.void
setBackground(Color background)
Defines the color for the background of the graph.void
setColor(Color color)
Defines the main color for the bars.void
setData(Number[] data)
Defines the numeric data for the drawable or null, if the drawable has no data.void
setHighColor(Color highColor)
Defines the color for the highest bars.void
setLastColor(Color lastColor)
Defines the color for the last bar.void
setSpacing(int spacing)
Defines the spacing between the bars.
-
-
-
Method Detail
-
getData
public Number[] getData()
Returns the numeric data for the drawable or null, if the drawable has no data.- Returns:
- the data.
-
setData
public void setData(Number[] data)
Defines the numeric data for the drawable or null, if the drawable has no data.- Parameters:
data
- the data (can be null).
-
getColor
public Color getColor()
Returns the main color for the bars.- Returns:
- the main color for the bars, never null.
-
setColor
public void setColor(Color color)
Defines the main color for the bars.- Parameters:
color
- the main color for the bars, never null.
-
getHighColor
public Color getHighColor()
Returns the color for the highest bars. This property is optional and the high-color can be null.- Returns:
- the color for the highest bars, or null if high bars should not be marked specially.
-
setHighColor
public void setHighColor(Color highColor)
Defines the color for the highest bars. This property is optional and the high-color can be null.- Parameters:
highColor
- the color for the highest bars, or null if high bars should not be marked specially.
-
getLastColor
public Color getLastColor()
Returns the color for the last bar. This property is optional and the last-bar-color can be null.- Returns:
- the color for the last bar in the graph, or null if last bars should not be marked specially.
-
setLastColor
public void setLastColor(Color lastColor)
Defines the color for the last bar. This property is optional and the last-bar-color can be null.- Parameters:
lastColor
- the color for the last bar in the graph, or null if last bars should not be marked specially.
-
getBackground
public Color getBackground()
Returns the color for the background of the graph. This property can be null, in which case the bar will have a transparent background.- Returns:
- color for the background or null, if the graph has a transparent background color.
-
setBackground
public void setBackground(Color background)
Defines the color for the background of the graph. This property can be null, in which case the bar will have a transparent background.- Parameters:
background
- the background or null, if the graph has a transparent background color.
-
getSpacing
public int getSpacing()
Returns the spacing between the bars.- Returns:
- the spacing between the bars.
-
setSpacing
public void setSpacing(int spacing)
Defines the spacing between the bars.- Parameters:
spacing
- the spacing between the bars.
-
draw
public void draw(Graphics2D g2, Rectangle2D drawArea)
Draws the bar-graph into the given Graphics2D context in the given area. This method will not draw a graph if the data given is null or empty.- Parameters:
g2
- the graphics context on which the bargraph should be rendered.drawArea
- the area on which the bargraph should be drawn.
-
-