All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class com.objectplanet.chart.LineChart

java.lang.Object
   |
   +----java.awt.Component
           |
           +----com.objectplanet.chart.Chart
                   |
                   +----com.objectplanet.chart.LineChart

public class LineChart
extends Chart
This class implements a line chart component. The line chart can have several series of data, and draws a line for each serie. One serie consists of a set of values which are connected by a line. The user can select a serie by clicking the serie label on the legend.

The following attributes can be set:

You can turn on or off the following features: The following code creates a line chart with 4 series with 10 samples each:
// create the chart and the samples
LineChart chart = new LineChart(4, 10, 1000);
long[] samples1 = new long[] {200, 300, 100, 400, 600, 500, 1000, 800, 700, 900};
long[] samples2 = new long[] {500, 200, 500, 300, 700, 300, 800, 900, 700, 600};
long[] samples3 = new long[] {600, 700, 900, 800, 400, 700, 400, 500, 300, 500};
long[] samples4 = new long[] {600, 700, 900, 800, 400, 700, 400, 500, 300, 500};
// set the samples for each of the series
chart.setSampleValues(0, samples1);
chart.setSampleValues(1, samples2);
chart.setSampleValues(2, samples3);
chart.setSampleValues(3, samples4);
// set the label for each of the series
chart.setSeriesLabel(0, "series 1");
chart.setSeriesLabel(1, "series 2");
chart.setSeriesLabel(2, "series 3");
chart.setSeriesLabel(3, "series 4");
// set the sample labels for the x-axis
for (int i = 0; i < chart.samples.length; i++) {
chart.setSampleLabel(i, "T"+i);
}
// set the chart title and turn on decired features
chart.setTitle("Line Chart");
chart.setTitleOn(true);
chart.setLegendOn(true);
chart.setValueLinesOn(true);
chart.setRangeAdjusterOn(true);
chart.setSampleLabelsOn(true);
 

Author:
Bjorn J. Kvande.

Variable Index

 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.

Constructor Index

 o LineChart()
Creates a line chart with one series, 5 samples, and a range of 0-100.
 o LineChart(int, int, double)
Creates a line chart with the specified number of series, the number of samples per serie, and the chart range.
 o LineChart(int, int, double, double)
Creates a line chart with the specified number of series, the number of samples per serie, and the chart range.

Method Index

 o appendSampleValue(int, double, boolean)
Appends a sample value after the current last value in the given series.
 o checkSelection(Point)
Checks if the given point is inside a sample.
 o getFloatLowerRange()
Gets the lower range of the chart as a floating point value.
 o getFloatMaxValue()
Gets the largest value in the chart as a floating point value.
 o getFloatMinValue()
Gets the lowest value in the chart as a floating point value.
 o getFloatRange()
Gets the upper range of the chart as a floating point value.
 o getFloatSampleValue(int, int)
Gets the specified sample in the given series as floating point.
 o getFloatSampleValues(int)
Gets the sample values for the specified series as floating point numbers.
 o getGraphBounds()
Calculates the bounding rectangle of the graph itself, based on which features are on and how they are configured.
 o getLineColor()
Gets the color of the line in use when only one series is in use. Deprecated.
 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 y-axis range values.
 o getSample(int, int)
Gets the specified sample from the given series.
 o getSamples(int)
Gets the samples from one series.
 o getSampleValue(int, int)
Gets the specified sample in the given series as an integer number.
 o getSampleValues(int)
Gets the sample values for the specified series.
 o getSeriesCount()
Returns the number of series in the chart.
 o getSeriesLabel(int)
Gets the label of the given series.
 o getSeriesLabels()
Gets the series labels as an array of strings.
 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 isRangeAdjusterOn()
Checks if the range adjuster is turned on.
 o isRangeLabelsOn()
Checks if the range labels are on or off.
 o isSampleLabelsOn()
Checks if the sample labels are turned on.
 o isValueLinesOn()
Checks if the value lines are turned on.
 o render(Graphics)
Renders the line chart according to the set attributes and the current features that are turned on.
 o setLineColor(Color)
Sets the line color when only one series is in use.
 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 setRange(double)
Sets the upper range of the chart.
 o setRangeAdjusterOn(boolean)
Turns on or off the range adjuster.
 o setRangeDecimalCount(int)
Sets the number of decimals to be used in the y-axis 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 lines in the chart.
 o setSampleColors(Color[])
Sets the sample colors.
 o setSampleCount(int)
Sets the number of samples for the chart.
 o setSampleLabelsOn(boolean)
Turns on the sample labels on the x-axis.
 o setSampleValue(int, int, double)
Sets on sample in the given serie.
 o setSampleValues(int, double[])
Sets the sample values of the given series as floating point values.
 o setSampleValues(int, long[])
Sets the sample values of the given series.
 o setSeriesCount(int)
Sets the number of series in the chart.
 o setSeriesLabel(int, String)
Sets the label of the given series.
 o setSeriesLabels(String[])
Sets the labels for the series.
 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 horizontal value lines.

Variables

 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 LineChart
 public LineChart()
Creates a line chart with one series, 5 samples, and a range of 0-100.

 o LineChart
 public LineChart(int seriesCount,
                  int sampleCount,
                  double range)
Creates a line chart with the specified number of series, the number of samples per serie, and the chart range.

Parameters:
seriesCount - The number of sample series.
sampleCount - The number of samples per series.
range - The upper range of the chart.
 o LineChart
 public LineChart(int seriesCount,
                  int sampleCount,
                  double range,
                  double lowerRange)
Creates a line chart with the specified number of series, the number of samples per serie, and the chart range.

Parameters:
seriesCount - The number of sample series.
sampleCount - The number of samples per series.
range - The upper range of the chart.
lowerRange - The lower range of the chart.

Methods

 o getSamples
 public ChartSample[] getSamples(int serie)
Gets the samples from one series.

Parameters:
serie - The index of the serie to get the samples from (0-based).
Returns:
An array of the chart samples.
 o getSample
 public ChartSample getSample(int serie,
                              int index)
Gets the specified sample from the given series.

Parameters:
serie - The index of the series to get the sample from (0-based).
index - The index of the sample to get (0-based).
 o setSampleValues
 public synchronized void setSampleValues(int serie,
                                          long values[])
Sets the sample values of the given series. This will be the sample values for one whole line in the chart.

Parameters:
serie - The index of the series to set (0-based).
values - The values to set as an array of longs.
 o setSampleValues
 public synchronized void setSampleValues(int serie,
                                          double values[])
Sets the sample values of the given series as floating point values. This will be the sample values for one whole line in the chart. If the chart contains more samples than the number of values put in, any trailing sample values will be set to null.

Parameters:
serie - The index of the series to set (0-based).
values - The values to set as an array of longs.
 o getSampleValues
 public long[] getSampleValues(int serie)
Gets the sample values for the specified series.

Parameters:
serie - The index of the serie to get the samples for.
Returns:
An array containing the integer values.
 o getFloatSampleValues
 public double[] getFloatSampleValues(int serie)
Gets the sample values for the specified series as floating point numbers.

Parameters:
serie - The index of the serie to get the samples for.
Returns:
A double array containing the floating point values.
 o setSampleValue
 public synchronized void setSampleValue(int serie,
                                         int index,
                                         double value)
Sets on sample in the given serie. This sets one point on a line.

Parameters:
serie - The index of the series to set (0-based).
index - The index of the sample to set (0-based).
value - The value to set.
 o getSampleValue
 public long getSampleValue(int serie,
                            int index)
Gets the specified sample in the given series as an integer number.

Parameters:
serie - The index of the series to get (0-based).
index - The index of the sample to get (0-based).
 o getFloatSampleValue
 public double getFloatSampleValue(int serie,
                                   int index)
Gets the specified sample in the given series as floating point.

Parameters:
serie - The index of the series to get (0-based).
index - The index of the sample to get (0-based).
 o appendSampleValue
 public synchronized void appendSampleValue(int serie,
                                            double value,
                                            boolean makeSpace)
Appends a sample value after the current last value in the given series. If the current number of values in the series is less than the sample count of the chart, the new value will be appended after the last value set. If all the values are set in the chart, the behavior depends on the makeSpace parameter.

Parameters:
serie - The series to append the value to.
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 setSeriesLabels
 public void setSeriesLabels(String labels[])
Sets the labels for the series. The labels are given as an array where the first label is the label of the first serie and so on.

Parameters:
labels - The labels as a string array.
 o getSeriesLabels
 public String[] getSeriesLabels()
Gets the series labels as an array of strings.

 o setSeriesLabel
 public void setSeriesLabel(int serie,
                            String label)
Sets the label of the given series. This is the label in the legend.

Parameters:
serie - The index of the series (0-based).
label - The label of the series.
 o getSeriesLabel
 public String getSeriesLabel(int serie)
Gets the label of the given series.

Parameters:
serie - The index of the series (0-based).
 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 lines are adjusted according to this value. The range can be set to lower than the largest value of a line, but the top of the line will be cut off at the top of the chart.

Parameters:
range - The range to set.
 o getRange
 public synchronized long getRange()
Gets the upper range of the chart.

 o getFloatRange
 public synchronized double getFloatRange()
Gets the upper range of the chart 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 lines are adjusted according to this value. The range can be set to larger than the lowest value of a line, but the bottom of the line will be cut off at the bottom of the chart.

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 lines 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 lines 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 in one line 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 be used in the y-axis range values.

Parameters:
count - The number of decimals to use.
 o getRangeDecimalCount
 public int getRangeDecimalCount()
Gets the number of decimals used in the y-axis range values.

 o getFloatMaxValue
 public double getFloatMaxValue()
Gets the largest value in the chart as a floating point value. This will be the largest value of all the series.

Returns:
The maximum value, if no samples are present, 0 is returned.
Overrides:
getFloatMaxValue in class Chart
 o getFloatMinValue
 public double getFloatMinValue()
Gets the lowest value in the chart as a floating point value. This will be the lowest value of all the series.

Returns:
The smalles value found, or 0 if no samples were found.
Overrides:
getFloatMinValue in class Chart
 o checkSelection
 protected ChartSample checkSelection(Point point)
Checks if the given point is inside a sample. This is called by the selection code when the user clicks the mouse button.

Parameters:
point - The point to check for.
Returns:
The sample selected, or null if none was selected.
Overrides:
checkSelection in class Chart
 o setSampleCount
 public synchronized void setSampleCount(int count)
Sets the number of samples for the chart. If the number of samples are less than the current count, the samples with index larger than the new count is discarded. If the new count is larger then the current, new samples are created and initialized to zero.

Parameters:
count - The number of samples.
Overrides:
setSampleCount in class Chart
 o setSeriesCount
 public void setSeriesCount(int count)
Sets the number of series in the chart. The number of series is the number of lines in the chart. If the current number of series is larger than the new one, the above series will be discarted. If the new series count is larger than the current one, new series is created with zero values and no labels.

Parameters:
count - The number of series.
 o getSeriesCount
 public int getSeriesCount()
Returns the number of series in the chart. This is the number of lines.

 o setSampleColors
 public void setSampleColors(Color colors[])
Sets the sample colors. If the number of samples is larger than the number of colors, the colors of the samples will cycle through the array. To use the default colors, use NULL as a parameter.

Parameters:
colors - An array with the colors to be used, null for default colors.
Overrides:
setSampleColors in class Chart
 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 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 setValueLinesOn
 public void setValueLinesOn(boolean on)
Turns on or off the horizontal 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 if they are turned on, false otherwise.
 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 setSampleLabelsOn
 public void setSampleLabelsOn(boolean on)
Turns on the sample labels on the x-axis. The sample labels are for the first series only, and will be the same for all the series. These labels are not the same as the ones in the legend.

Parameters:
on - True for on, false for off.
 o isSampleLabelsOn
 public boolean isSampleLabelsOn()
Checks if the sample labels are turned on.

Returns:
True if they are turned on, false otherwise.
 o setRangeAdjusterOn
 public void setRangeAdjusterOn(boolean on)
Turns on or off the range adjuster. When this is on, the user can adjust the range to see any low-value lines more clearly.

Parameters:
on - True for on, false for off.
See Also:
setRange
 o isRangeAdjusterOn
 public boolean isRangeAdjusterOn()
Checks if the range adjuster is turned on.

Returns:
True if turned on, false otherwise.
 o setLineColor
 public void setLineColor(Color color)
Sets the line color when only one series is in use.

Parameters:
color - The color to set.
deprecated - Use setSampleColor(0, color) instead.
 o getLineColor
 public Color getLineColor()
Note: getLineColor() is deprecated. Use getSampleColor(0) instead.

Gets the color of the line in use when only one series is in use.

 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 render
 public void render(Graphics g)
Renders the line chart according to the set attributes and the current features that are turned on. and GUI state values.

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