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:

You can turn on or off the following features: 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);
 

Author:
Bjorn J. Kvande

Variable Index

 o HORIZONTAL
Horizontal bar alignment.
 o TARGET_LINE_ID_AND_VALUE_LABEL
Use both the ID and value label with the target lines.
 o TARGET_LINE_ID_LABEL
Use the ID label with the target lines.
 o TARGET_LINE_NO_LABEL
Use no label with the target lines.
 o TARGET_LINE_VALUE_LABEL
Use the value label with the target lines.
 o VERTICAL
Vertical bar alignment.

Constructor Index

 o BarChart()
Createa a bar chart with 5 samples and a range of 100.
 o BarChart(int)
Creates a bar chart with the given number of bars and default range.
 o BarChart(int, double)
Creates a bar chart with the given number of bars and range.
 o BarChart(int, double, double)
Creates a bar chart with the given number of bars and range.

Method Index

 o appendSampleValue(double, boolean)
Appends a sample value after the current last value.
 o 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.
 o getBarAlignment()
Gets the bar alignment.
 o getBarColor()
Gets the color of the bars in single color mode. Deprecated.
 o getFloatLowerRange()
Gets the lower range of the chart as a floating point value.
 o getFloatRange()
Gets the upper range of the charts as a floating point value.
 o getGraphBounds()
Calculates the bounding rectangle of the graph itself, based on which features are on and how they are configured.
 o getLowerRange()
Gets the lower range of the chart.
 o getRange()
Gets the upper range of the chart.
 o getRangeDecimalCount()
Gets the number of decimals used in the range values.
 o getTargetValueLine(String)
Gets the value of a target value line.
 o getValueLinesColor()
Gets the color of the value lines.
 o getValuePosition(double)
Gets the position in the chart of the specified value.
 o isBarLabelsOn()
Checks if the bar labels are turned on.
 o isMultiColorOn()
Checks if the multicolor mode is turned on.
 o isRangeLabelsOn()
Checks if the range labels are on or off.
 o isValueLinesOn()
Checks if the value lines are turned on.
 o render(Graphics)
Renders the bar chart according to the current chart attributes and which charts features are turned on or off.
 o setBarAlignment(int)
Sets the bar alignment.
 o setBarColor(Color)
Sets the bar color. Deprecated.
 o setBarLabelsOn(boolean)
Turns on or off the bar labels.
 o setLowerRange(double)
Sets the lower range of the chart.
 o setLowerRelativeRange(double)
Sets the lower range of the chart relative to the current minimum value.
 o setMultiColorOn(boolean)
Turns on or off multi-color bar display.
 o setRange(double)
Sets the upper range of the chart.
 o setRangeDecimalCount(int)
Sets the number of decimals to use in the range values.
 o setRangeLabelsOn(boolean)
Turns on or off the range value labels.
 o setRelativeRange(double)
Sets the upper range of the chart relative to the maximum value of the bars in the chart.
 o setSampleCount(int)
Sets the number of bars for the chart.
 o setTargetValueLine(String, double, Color, int)
Sets a target value line with the specified ID, value, and color.
 o setValueLinesColor(Color)
Sets the color of the value lines in the chart.
 o setValueLinesOn(boolean)
Turns on or off the chart value lines.

Variables

 o HORIZONTAL
 public static final int HORIZONTAL
Horizontal bar alignment.

 o VERTICAL
 public static final int VERTICAL
Vertical bar alignment.

 o TARGET_LINE_NO_LABEL
 public static final int TARGET_LINE_NO_LABEL
Use no label with the target lines.

 o TARGET_LINE_ID_LABEL
 public static final int TARGET_LINE_ID_LABEL
Use the ID label with the target lines.

 o TARGET_LINE_VALUE_LABEL
 public static final int TARGET_LINE_VALUE_LABEL
Use the value label with the target lines.

 o 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.

Constructors

 o BarChart
 public BarChart()
Createa a bar chart with 5 samples and a range of 100.

 o 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.
 o 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.
 o 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.

Methods

 o 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.
 o 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
 o 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.
 o 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.

 o getFloatRange
 public synchronized double getFloatRange()
Gets the upper range of the charts as a floating point value.

 o 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.
 o getLowerRange
 public synchronized long getLowerRange()
Gets the lower range of the chart.

 o getFloatLowerRange
 public synchronized double getFloatLowerRange()
Gets the lower range of the chart as a floating point value.

 o 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->);
 o 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;
 o 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.
 o getRangeDecimalCount
 public int getRangeDecimalCount()
Gets the number of decimals used in the range values.

 o 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.
 o 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
 o isMultiColorOn
 public boolean isMultiColorOn()
Checks if the multicolor mode is turned on.

Returns:
True if multicolor, false otherwise.
 o 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
 o isBarLabelsOn
 public boolean isBarLabelsOn()
Checks if the bar labels are turned on.

Returns:
True for on, false for off.
 o 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.
 o isValueLinesOn
 public boolean isValueLinesOn()
Checks if the value lines are turned on.

Returns:
True for on, false for off.
 o setValueLinesColor
 public void setValueLinesColor(Color color)
Sets the color of the value lines in the chart.

Parameters:
color - The color to use.
 o getValueLinesColor
 public Color getValueLinesColor()
Gets the color of the value lines.

 o 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.
 o isRangeLabelsOn
 public boolean isRangeLabelsOn()
Checks if the range labels are on or off.

Returns:
True for on, false for off.
 o 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.
 o 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.
 o 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
 o getBarColor
 public Color getBarColor()
Note: getBarColor() is deprecated. Use getSampleColor(0) instead.

Gets the color of the bars in single color mode.

 o setBarAlignment
 public void setBarAlignment(int alignment)
Sets the bar alignment. The default alignment is vertical.

Parameters:
alignment - HORIZONTAL or VERTICAL.
 o getBarAlignment
 public int getBarAlignment()
Gets the bar alignment.

Returns:
HORIZONTAL or VERTICAL.
See Also:
setBarAlignment
 o 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
 o 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
 o 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