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.
-
label
- The label of the sample.
-
value
- The value of the sample.
-
ChartSample(int)
-
Creates a new empty sample with the given index.
-
ChartSample(int, long, String, Object)
-
Creates a new sample with the given values.
-
formatNumber(double, int)
- Formats a floating number to the number of decimals given.
-
getFloatValue()
- Gets the value as a floating point.
-
getIndex()
- Gets the index of the sample.
-
getKey()
- Gets the key of the sample.
-
getLabel()
- Gets the label of the sample.
-
getValue()
- Gets the value of the sample.
-
isSelected()
- Checks if the sample is selected.
-
set(double, String, Object)
- Sets the chart sample's value, label, and the key.
-
setLabel(String)
- Sets the label of the sample.
-
setLabelColor(Color)
- Sets the label color.
-
setSelection(boolean)
- Selects or de-selects the sample.
-
setValue(double)
- Sets the value of the sample.
-
toggleSelection()
- Toggles the selection of the sample.
-
toString()
- Returns the label and value as a string.
value
protected Double value
- The value of the sample.
label
protected String label
- The label of the sample.
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).
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.
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.
setValue
public void setValue(double value)
- Sets the value of the sample.
- Parameters:
- value - The value to set.
getValue
public long getValue()
- Gets the value of the sample.
getFloatValue
public double getFloatValue()
- Gets the value as a floating point.
setLabel
public void setLabel(String label)
- Sets the label of the sample.
- Parameters:
- label - The label to set.
getLabel
public String getLabel()
- Gets the label of the sample.
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.
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.
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.
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.
isSelected
public boolean isSelected()
- Checks if the sample is selected.
- Returns:
- True for selected, false otherwise.
toggleSelection
public boolean toggleSelection()
- Toggles the selection of the sample.
- Returns:
- The new state of the sample.
toString
public String toString()
- Returns the label and value as a string.
- Overrides:
- toString in class Object
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