Class BarGraphDrawable
java.lang.Object
org.pentaho.reporting.libraries.libsparklines.BarGraphDrawable
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
ConstructorDescriptionCreates a default bargraph drawable with some sensible default colors and spacings. -
Method Summary
Modifier and TypeMethodDescriptionvoid
draw
(Graphics2D g2, Rectangle2D drawArea) Draws the bar-graph into the given Graphics2D context in the given area.Returns the color for the background of the graph.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.Returns the color for the highest bars.Returns the color for the last bar.int
Returns the spacing between the bars.void
setBackground
(Color background) Defines the color for the background of the graph.void
Defines the main color for the bars.void
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.
-
Constructor Details
-
BarGraphDrawable
public BarGraphDrawable()Creates a default bargraph drawable with some sensible default colors and spacings.
-
-
Method Details
-
getData
Returns the numeric data for the drawable or null, if the drawable has no data.- Returns:
- the data.
-
setData
Defines the numeric data for the drawable or null, if the drawable has no data.- Parameters:
data
- the data (can be null).
-
getColor
Returns the main color for the bars.- Returns:
- the main color for the bars, never null.
-
setColor
Defines the main color for the bars.- Parameters:
color
- the main color for the bars, never null.
-
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
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
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
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
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
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
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.
-