All Packages Class Hierarchy This Package Previous Next Index
Class com.objectplanet.chart.BarChart
java.lang.Object
|
+----java.awt.Component
|
+----com.objectplanet.chart.Chart
|
+----com.objectplanet.chart.BarChart
- public class BarChart
- extends Chart
This class implements a barchart component. The barchart can both be
displayed in 2D and 3D mode. The bars can also be displayed in
vertical and horizontal alignment. The bars as well as the legend
label can be selected by the user.
The following attributes can be set:
- the chart title
- the chart title font
- the legend position
- the legend label colors
- the upper range of the chart
- the lower range of the chart
- the number of decimals used for the range values
- the number of decimals used for the value labels
- the bar alignment (vertical or horizontal)
- the color of each bar can be set
- the font used for the value and sample labels
- the chart background color
- the chart foreground color
- target value lines can be set with specified colors
You can turn on or off the following features:
- 2D or 3D display
- the chart title
- the chart legend
- the bar value labels
- the bar labels
- the value lines
- single or multicolor
The following code creates a bar chart with five samples.
// create the chart and its samples
BarChart chart = new BarChart(4, 1000);
long[] values = new long[] {200, 400, 600, 800};
String[] labels = new String[] {"one", "two", "three", "four"};
// set the chart attributes
chart.setTitle("Bar Chart");
chart.setSampleValues(values);
chart.setSampleLabels(labels);
// set the chart features
chart.set3DModeOn(true);
chart.setMultiColorOn(true);
chart.setValueLinesOn(true);
chart.setTitleOn(true);
chart.setLegendOn(true);
chart.setValueLabelsOn(true);
- Range is set to 1000
- Sample values are set to 200, 400, 600, and 800.
- Sample labels are set to "one", "two", "three", and "four"
- The chart title is set to "Bar Chart".
- 3D mode turned on
- Multicolor turned on
- Valuelines turned on
- Chart title turned on
- Legend turned on
- Valuelabels turned on
- Author:
- Bjorn J. Kvande
-
HORIZONTAL
- Horizontal bar alignment.
-
TARGET_LINE_ID_AND_VALUE_LABEL
- Use both the ID and value label with the target lines.
-
TARGET_LINE_ID_LABEL
- Use the ID label with the target lines.
-
TARGET_LINE_NO_LABEL
- Use no label with the target lines.
-
TARGET_LINE_VALUE_LABEL
- Use the value label with the target lines.
-
VERTICAL
- Vertical bar alignment.
-
BarChart()
- Createa a bar chart with 5 samples and a range of 100.
-
BarChart(int)
- Creates a bar chart with the given number of bars and default range.
-
BarChart(int, double)
- Creates a bar chart with the given number of bars and range.
-
BarChart(int, double, double)
- Creates a bar chart with the given number of bars and range.
-
appendSampleValue(double, boolean)
- Appends a sample value after the current last value.
-
checkSelection(Point)
- This method is called when the user releases the mouse and checks
if the given point is inside a bar or a legend label.
-
getBarAlignment()
- Gets the bar alignment.
-
getBarColor()
- Gets the color of the bars in single color mode.
Deprecated.
-
getFloatLowerRange()
- Gets the lower range of the chart as a floating point value.
-
getFloatRange()
- Gets the upper range of the charts as a floating point value.
-
getGraphBounds()
-
Calculates the bounding rectangle of the graph itself,
based on which features are on and how they are configured.
-
getLowerRange()
- Gets the lower range of the chart.
-
getRange()
- Gets the upper range of the chart.
-
getRangeDecimalCount()
- Gets the number of decimals used in the range values.
-
getTargetValueLine(String)
- Gets the value of a target value line.
-
getValueLinesColor()
- Gets the color of the value lines.
-
getValuePosition(double)
- Gets the position in the chart of the specified value.
-
isBarLabelsOn()
- Checks if the bar labels are turned on.
-
isMultiColorOn()
- Checks if the multicolor mode is turned on.
-
isRangeLabelsOn()
- Checks if the range labels are on or off.
-
isValueLinesOn()
- Checks if the value lines are turned on.
-
render(Graphics)
- Renders the bar chart according to the current chart attributes
and which charts features are turned on or off.
-
setBarAlignment(int)
- Sets the bar alignment.
-
setBarColor(Color)
- Sets the bar color.
Deprecated.
-
setBarLabelsOn(boolean)
- Turns on or off the bar labels.
-
setLowerRange(double)
- Sets the lower range of the chart.
-
setLowerRelativeRange(double)
- Sets the lower range of the chart relative to the current minimum value.
-
setMultiColorOn(boolean)
- Turns on or off multi-color bar display.
-
setRange(double)
- Sets the upper range of the chart.
-
setRangeDecimalCount(int)
- Sets the number of decimals to use in the range values.
-
setRangeLabelsOn(boolean)
- Turns on or off the range value labels.
-
setRelativeRange(double)
- Sets the upper range of the chart relative to the maximum value of the bars
in the chart.
-
setSampleCount(int)
- Sets the number of bars for the chart.
-
setTargetValueLine(String, double, Color, int)
- Sets a target value line with the specified ID, value, and color.
-
setValueLinesColor(Color)
- Sets the color of the value lines in the chart.
-
setValueLinesOn(boolean)
- Turns on or off the chart value lines.
HORIZONTAL
public static final int HORIZONTAL
- Horizontal bar alignment.
VERTICAL
public static final int VERTICAL
- Vertical bar alignment.
TARGET_LINE_NO_LABEL
public static final int TARGET_LINE_NO_LABEL
- Use no label with the target lines.
TARGET_LINE_ID_LABEL
public static final int TARGET_LINE_ID_LABEL
- Use the ID label with the target lines.
TARGET_LINE_VALUE_LABEL
public static final int TARGET_LINE_VALUE_LABEL
- Use the value label with the target lines.
TARGET_LINE_ID_AND_VALUE_LABEL
public static final int TARGET_LINE_ID_AND_VALUE_LABEL
- Use both the ID and value label with the target lines.
BarChart
public BarChart()
- Createa a bar chart with 5 samples and a range of 100.
BarChart
public BarChart(int count)
- Creates a bar chart with the given number of bars and default range.
The default range is 100.
- Parameters:
- count - The number of bars for the chart.
BarChart
public BarChart(int count,
double range)
- Creates a bar chart with the given number of bars and range.
- Parameters:
- count - The number of bars for the chart.
- range - The initial range of the chart.
BarChart
public BarChart(int count,
double range,
double lowerRange)
- Creates a bar chart with the given number of bars and range.
- Parameters:
- count - The number of bars for the chart.
- range - The initial upper range of the chart.
- lowerRange - The initial lower range of the chart.
appendSampleValue
public synchronized void appendSampleValue(double value,
boolean makeSpace)
- Appends a sample value after the current last value. If the
current number of values is less than the sample count of the
chart, the new value will be appended after the last set value.
If all the values are set in the chart, the behavior depends
on the makeSpace parameter.
- Parameters:
- value - The value to append.
- makeSpace - True if the the sample count should be increased,
false if the rest of the samples should scroll.
setSampleCount
public void setSampleCount(int count)
- Sets the number of bars for the chart. If the number of bars are less
than the current count, the bars with index larger than the new count
is discarded. If the new count is larger then the current, new bars
are created and initialized to zero.
- Parameters:
- count - The number of bars.
- Overrides:
- setSampleCount in class Chart
setRange
public synchronized void setRange(double range)
- Sets the upper range of the chart. The upper range is the
maximum value on the value axis, and the bars are adjusted
according to this value.
- Parameters:
- range - The range to set.
getRange
public synchronized long getRange()
- Gets the upper range of the chart. The upper range is the maximum value on
the value axis, and the bars are adjusted according to this value.
getFloatRange
public synchronized double getFloatRange()
- Gets the upper range of the charts as a floating point value.
setLowerRange
public synchronized void setLowerRange(double range)
- Sets the lower range of the chart. The lower range is the minimum
value on the value axis, and the bars are adjusted according to this value.
- Parameters:
- range - The range to set.
getLowerRange
public synchronized long getLowerRange()
- Gets the lower range of the chart.
getFloatLowerRange
public synchronized double getFloatLowerRange()
- Gets the lower range of the chart as a floating point value.
setRelativeRange
public synchronized void setRelativeRange(double range)
- Sets the upper range of the chart relative to the maximum value of the bars
in the chart. If the maximum value is 1000, and the upper range is set to
1.5, the new range will be 1500, and the bars will be adjusted according
to the new range. If all the values are negative, the upper range will
be set to 0.
- Parameters:
- range - The relative range (1.0->);
setLowerRelativeRange
public synchronized void setLowerRelativeRange(double range)
- Sets the lower range of the chart relative to the current minimum value.
If the lowest value is -1000, and the lower range is set to
1.5, the new lower range will then be -1500. If all the values are
positive, the lower range will be set to 0.
- Parameters:
- range - The relative range;
setRangeDecimalCount
public void setRangeDecimalCount(int count)
- Sets the number of decimals to use in the range values.
If you have a very low range, you might want to increase the number
of decimals, otherwise the range values will be squewed.
The default is 0 decimals.
- Parameters:
- count - The number of decimals to use.
getRangeDecimalCount
public int getRangeDecimalCount()
- Gets the number of decimals used in the range values.
getValuePosition
public int getValuePosition(double value)
- Gets the position in the chart of the specified value. If the alignment
of the bars is VERTICAL the position represents the y-axis. If the
alignment of the bars is HORIZONTAL the position represents the x-axis.
- Parameters:
- value - The value to find the position for.
- Returns:
- The pixel position.
setMultiColorOn
public void setMultiColorOn(boolean on)
- Turns on or off multi-color bar display.
- Parameters:
- on - True for multi-color, false for single-color.
- See Also:
- setBarColor
isMultiColorOn
public boolean isMultiColorOn()
- Checks if the multicolor mode is turned on.
- Returns:
- True if multicolor, false otherwise.
setBarLabelsOn
public void setBarLabelsOn(boolean on)
- Turns on or off the bar labels. The bar labels are the same as the
labels in the legend, but are displayed at the base of the bar itself.
- Parameters:
- on - True if the bar labels should be displayed.
- See Also:
- setSampleLabel
isBarLabelsOn
public boolean isBarLabelsOn()
- Checks if the bar labels are turned on.
- Returns:
- True for on, false for off.
setValueLinesOn
public void setValueLinesOn(boolean on)
- Turns on or off the chart value lines. There are initially 20 lines in
the chart, but the number of lines are halved if there is not enough
room for the lines, and then halved again until there is enough room.
- Parameters:
- on - True for on, false for off.
isValueLinesOn
public boolean isValueLinesOn()
- Checks if the value lines are turned on.
- Returns:
- True for on, false for off.
setValueLinesColor
public void setValueLinesColor(Color color)
- Sets the color of the value lines in the chart.
- Parameters:
- color - The color to use.
getValueLinesColor
public Color getValueLinesColor()
- Gets the color of the value lines.
setRangeLabelsOn
public void setRangeLabelsOn(boolean on)
- Turns on or off the range value labels. They are on by default.
- Parameters:
- on - True for on, false for off.
isRangeLabelsOn
public boolean isRangeLabelsOn()
- Checks if the range labels are on or off.
- Returns:
- True for on, false for off.
setTargetValueLine
public void setTargetValueLine(String id,
double value,
Color color,
int style)
- Sets a target value line with the specified ID, value, and color.
- Parameters:
- id - The id of the target line.
- value - The value where the line should appear.
- color - The color of the line, if null, the line is removed.
- style - TARGET_LINE_NO_LABEL, TARGET_LINE_ID_LABEL,
TARGET_LINE_VALUE_LABEL, or TARGET_LINE_ID_AND_VALUE_LABEL.
getTargetValueLine
public double getTargetValueLine(String id)
- Gets the value of a target value line.
- Parameters:
- id - The id of the target line.
- Returns:
- The value of the line.
setBarColor
public void setBarColor(Color color)
- Note: setBarColor() is deprecated.
Use setSampleColor(0, color) instead.
- Sets the bar color. This is the color of the bars when the chart
is in single color mode.
- Parameters:
- color - The color to set.
- See Also:
- setMultiColorOn
getBarColor
public Color getBarColor()
- Note: getBarColor() is deprecated.
Use getSampleColor(0) instead.
- Gets the color of the bars in single color mode.
setBarAlignment
public void setBarAlignment(int alignment)
- Sets the bar alignment. The default alignment is vertical.
- Parameters:
- alignment - HORIZONTAL or VERTICAL.
getBarAlignment
public int getBarAlignment()
- Gets the bar alignment.
- Returns:
- HORIZONTAL or VERTICAL.
- See Also:
- setBarAlignment
checkSelection
protected ChartSample checkSelection(Point point)
- This method is called when the user releases the mouse and checks
if the given point is inside a bar or a legend label.
- Parameters:
- point - The point clicked on.
- Returns:
- The bar selected, or null if no bar was selected.
- Overrides:
- checkSelection in class Chart
render
public void render(Graphics g)
- Renders the bar chart according to the current chart attributes
and which charts features are turned on or off.
- Overrides:
- render in class Chart
getGraphBounds
public Rectangle getGraphBounds()
- Calculates the bounding rectangle of the graph itself,
based on which features are on and how they are configured.
All Packages Class Hierarchy This Package Previous Next Index