All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class com.objectplanet.chart.ChartSample

java.lang.Object
   |
   +----com.objectplanet.chart.ChartSample

public class ChartSample
extends Object
implements Serializable
This class represents a sample in any chart. A chart sample has a value, label, label color, and a key. Each sample also has an index, which is the sample's position in the chart. A sample can also be selected.

Author:
Bjorn J. Kvande.

Variable Index

 o label
The label of the sample.
 o value
The value of the sample.

Constructor Index

 o ChartSample(int)
Creates a new empty sample with the given index.
 o ChartSample(int, long, String, Object)
Creates a new sample with the given values.

Method Index

 o formatNumber(double, int)
Formats a floating number to the number of decimals given.
 o getFloatValue()
Gets the value as a floating point.
 o getIndex()
Gets the index of the sample.
 o getKey()
Gets the key of the sample.
 o getLabel()
Gets the label of the sample.
 o getValue()
Gets the value of the sample.
 o isSelected()
Checks if the sample is selected.
 o set(double, String, Object)
Sets the chart sample's value, label, and the key.
 o setLabel(String)
Sets the label of the sample.
 o setLabelColor(Color)
Sets the label color.
 o setSelection(boolean)
Selects or de-selects the sample.
 o setValue(double)
Sets the value of the sample.
 o toggleSelection()
Toggles the selection of the sample.
 o toString()
Returns the label and value as a string.

Variables

 o value
 protected Double value
The value of the sample.

 o label
 protected String label
The label of the sample.

Constructors

 o ChartSample
 public ChartSample(int index)
Creates a new empty sample with the given index.

Parameters:
index - The index of the sample (should be position in the chart).
 o ChartSample
 public ChartSample(int index,
                    long value,
                    String label,
                    Object key)
Creates a new sample with the given values.

Parameters:
index - The index of the sample (should be position in the chart).
value - The value of the sample.
label - The label of the sample.
key - The key of the sample.

Methods

 o set
 public void set(double value,
                 String label,
                 Object key)
Sets the chart sample's value, label, and the key. The key is used to look up the sample in the chart again if it changed place in the chart.

Parameters:
value - The value of the sample.
label - The label of the sample.
key - The key of the sample.
 o setValue
 public void setValue(double value)
Sets the value of the sample.

Parameters:
value - The value to set.
 o getValue
 public long getValue()
Gets the value of the sample.

 o getFloatValue
 public double getFloatValue()
Gets the value as a floating point.

 o setLabel
 public void setLabel(String label)
Sets the label of the sample.

Parameters:
label - The label to set.
 o getLabel
 public String getLabel()
Gets the label of the sample.

 o setLabelColor
 public void setLabelColor(Color color)
Sets the label color. This is the color of the label in the legend. The default label color is black.

Parameters:
color - The color to use.
 o getIndex
 public int getIndex()
Gets the index of the sample. This is the position of the sample in the chart. The index will change if the sample changes position in the chart.

 o getKey
 public Object getKey()
Gets the key of the sample. The key is used to look up the sample in the chart again if it changed place in the chart.

Returns:
The key, or null if there is no key for this sample.
 o setSelection
 public boolean setSelection(boolean state)
Selects or de-selects the sample.

Parameters:
state - True for selected, false otherwise.
Returns:
The new state of the sample.
 o isSelected
 public boolean isSelected()
Checks if the sample is selected.

Returns:
True for selected, false otherwise.
 o toggleSelection
 public boolean toggleSelection()
Toggles the selection of the sample.

Returns:
The new state of the sample.
 o toString
 public String toString()
Returns the label and value as a string.

Overrides:
toString in class Object
 o formatNumber
 public static String formatNumber(double value,
                                   int decimals)
Formats a floating number to the number of decimals given. The formatted number will have the integer part paired in three and three.

Parameters:
value - The value to format.
decimals - The number of decimals to use.
Returns:
A string with the formatted number.

All Packages  Class Hierarchy  This Package  Previous  Next  Index