|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--java.awt.Component | +--com.objectplanet.chart.Chart | +--com.objectplanet.chart.LineChart
This line chart component enables you to add a line chart to your java
applications with just a few lines of code.
A simple line chart can be created with the following code:
See here for a list of parameters to
set for the line chart.
LineChart chart = new LineChart();
long[] values = new long[] {20, 10, 30, 50, 40};
chart.setSampleValues(values);
A chart with several data series can be created with the following code:
LineChart chart = new LineChart(4, 10, 100);
long[] series0 = new long[] {98,23,46,89,72,36,49,87,23,64};
long[] series1 = new long[] {80,17,92,63,98,16,53,86,52,34};
long[] series2 = new long[] {29,83,46,93,80,72,36,42,98,36};
long[] series3 = new long[] {45,86,90,86,54,65,98,75,44,54};
chart.setSampleValues(0, series0);
chart.setSampleValues(1, series1);
chart.setSampleValues(2, series2);
chart.setSampleValues(3, series3);
Nested Class Summary |
Nested classes inherited from class java.awt.Component |
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy |
Field Summary | |
static int |
SAMPLE_HIGHLIGHT_CIRCLE
Use a circle as a sample highlighter on a line. |
static int |
SAMPLE_HIGHLIGHT_CIRCLE_FILLED
Use a filled circle as a sample highlighter on a line. |
static int |
SAMPLE_HIGHLIGHT_CIRCLE_OPAQUE
Use an opaque circle as a sample highlighter on a line. |
static int |
SAMPLE_HIGHLIGHT_DIAMOND
Use a diamond as a sample highlighter on a line. |
static int |
SAMPLE_HIGHLIGHT_DIAMOND_FILLED
Use a filled diamond as a sample highlighter on a line. |
static int |
SAMPLE_HIGHLIGHT_DIAMOND_OPAQUE
Use an opaque diamond as a sample highlighter on a line. |
static int |
SAMPLE_HIGHLIGHT_SQUARE
Use a square as a sample highlighter on a line. |
static int |
SAMPLE_HIGHLIGHT_SQUARE_FILLED
Use a filled square as a sample highlighter on a line. |
static int |
SAMPLE_HIGHLIGHT_SQUARE_OPAQUE
Use an opaque square as a sample highlighter on a line. |
Fields inherited from class com.objectplanet.chart.Chart |
BELOW, BELOW_AND_FLOATING, BOTTOM, chartData, FLOATING, HORIZONTAL, INSIDE, LEFT, OUTSIDE, overlayCharts, RIGHT, STATIC, TARGET_LINE_ID_AND_VALUE_LABEL, TARGET_LINE_ID_LABEL, TARGET_LINE_NO_LABEL, TARGET_LINE_VALUE_LABEL, TOP, VERTICAL, visibleSamples |
Fields inherited from class java.awt.Component |
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT |
Fields inherited from interface java.awt.image.ImageObserver |
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH |
Constructor Summary | |
LineChart()
Creates a line chart with one series, 5 samples, and a range of 0-100. |
|
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. |
|
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. |
Method Summary | |
protected void |
calculateChartData(java.awt.Rectangle grid,
java.awt.Rectangle dataBounds)
Calculates chart data. |
protected void |
checkDataIntegrity()
Makes sure the linechart specific data has the same number of series and samples as the chart data has. |
com.objectplanet.chart.ChartSample |
checkSelection(java.awt.Point point)
If we select a box in the legend, it returns a ChartSample with the correct series, but the sample is set to -1. |
java.awt.Rectangle |
getGraphBounds()
Calculates the bounding rectangle of the graph itself, based on which features are on and how they are configured. |
java.lang.String[] |
getLegendLabels()
Gets the legend labels. |
int |
getLineWidth(int series)
Gets the current width of the given series line. |
double |
getMaxValue(int serie)
Gets the maximum value in the chart. |
int |
getSampleHighlightSize(int series)
Gets the sample highlight size. |
int |
getSampleHighlightStyle(int series)
Gets the sample highlight style. |
int |
getValueLabelStyle()
Gets the value label style. |
int |
getValuePosition(double value)
Gets the position in the chart of the specified value. |
boolean |
isAutoLabelSpacingOn()
Gets the state of the automatic label spacing. |
boolean |
isConnectedLinesOn(int serie)
Checks if lines with missing values are connected. |
boolean |
isRightToLeftScrollingOn()
Checks if the right to left scrolling is turned on. |
boolean |
isSampleHighlightOn(int series,
int sample)
Checks if the sample highlight is turned on or off for a sample. |
boolean |
isSeriesLineOn(int serie)
Checks if the specified line is on. |
boolean |
isStackedOn()
Checks if stacked lines are turned on. |
void |
render(java.awt.Graphics g)
Renders the line chart according to the set attributes and the current features that are turned on. |
protected void |
renderData(java.awt.Graphics g,
java.awt.Rectangle grid,
java.awt.Rectangle dataBounds)
Renders the lines for the chart. |
void |
reset()
Resets the chart data and features. |
void |
setAutoLabelSpacingOn(boolean on)
Turns on or off automatic sample label spacing. |
void |
setConnectedLinesOn(int serie,
boolean on)
Connects lines with missing values. |
void |
setLegendImage(int index,
java.lang.String name)
Sets an image to be used in front of the legend label and as the sample highlight for the specified series. |
void |
setLineWidth(int series,
int width)
Sets the width of the specified line. |
void |
setRightToLeftScrollingOn(boolean state)
Turns on right to left scrolling when adding new values. |
void |
setSampleColors(java.awt.Color[] colors)
Sets the sample colors. |
void |
setSampleHighlightOn(boolean on)
Turns on or off the sample highlight for the data series. |
void |
setSampleHighlightOn(int series,
boolean on)
Turns on or off the sample highlight for a data series. |
void |
setSampleHighlightOn(int series,
int sample,
boolean on)
Turns on or off the sample highlight for a sample in a data series. |
void |
setSampleHighlightStyle(int style,
int size)
Sets the sample highlight style for all the data series. |
void |
setSampleHighlightStyle(int serie,
int style,
int size)
Sets the sample highlight style for the specified data series. |
void |
setSeriesLineOn(boolean state)
Turns on or off the series lines. |
void |
setSeriesLineOn(int serie,
boolean state)
Turns on or off the specified series line. |
void |
setStackedOn(boolean on)
Turns on or off stacked lines. |
void |
setValueLabelStyle(int style)
Sets the value label style. |
Methods inherited from class java.awt.Component |
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createVolatileImage, createVolatileImage, deliverEvent, disable, disableEvents, dispatchEvent, doLayout, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, getAccessibleContext, getAlignmentX, getAlignmentY, getBackground, getBounds, getBounds, getColorModel, getComponentAt, getComponentAt, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeys, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getListeners, getLocale, getLocation, getLocation, getLocationOnScreen, getMaximumSize, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, invalidate, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusCycleRoot, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isOpaque, isShowing, isValid, isVisible, keyDown, keyUp, layout, list, list, list, list, list, locate, location, lostFocus, minimumSize, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, paramString, postEvent, preferredSize, prepareImage, prepareImage, printAll, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeys, setFocusTraversalKeysEnabled, setFont, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, setVisible, show, show, size, transferFocus, transferFocusBackward, transferFocusUpCycle, validate |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
public static final int SAMPLE_HIGHLIGHT_CIRCLE
public static final int SAMPLE_HIGHLIGHT_CIRCLE_FILLED
public static final int SAMPLE_HIGHLIGHT_CIRCLE_OPAQUE
public static final int SAMPLE_HIGHLIGHT_DIAMOND
public static final int SAMPLE_HIGHLIGHT_DIAMOND_FILLED
public static final int SAMPLE_HIGHLIGHT_DIAMOND_OPAQUE
public static final int SAMPLE_HIGHLIGHT_SQUARE
public static final int SAMPLE_HIGHLIGHT_SQUARE_FILLED
public static final int SAMPLE_HIGHLIGHT_SQUARE_OPAQUE
Constructor Detail |
public LineChart()
public LineChart(int seriesCount, int sampleCount, double range)
seriesCount
- The number of sample series.sampleCount
- The number of samples per series.range
- The upper range of the chart.
java.lang.IllegalArgumentException
- If the seriesCount is less than 1public LineChart(int seriesCount, int sampleCount, double range, double lowerRange)
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.
java.lang.IllegalArgumentException
- If the seriesCount is less than 1Method Detail |
protected void calculateChartData(java.awt.Rectangle grid, java.awt.Rectangle dataBounds)
calculateChartData
in class Chart
grid
- The chart grid.dataBounds
- The scrolled data bounds.protected void checkDataIntegrity()
checkDataIntegrity
in class Chart
public com.objectplanet.chart.ChartSample checkSelection(java.awt.Point point)
checkSelection
in class Chart
point
- The point to check for.
public java.awt.Rectangle getGraphBounds()
getGraphBounds
in class Chart
public java.lang.String[] getLegendLabels()
getLegendLabels
in class Chart
Chart.setLegendLabels(java.lang.String[])
public int getLineWidth(int series)
series
- The index of the data series.
public double getMaxValue(int serie)
getMaxValue
in class Chart
serie
- The index of the series.public int getSampleHighlightSize(int series)
series
- The series to get the size for.
java.lang.IllegalArgumentException
- if the series is invalid.public int getSampleHighlightStyle(int series)
series
- The series to get the style for.
java.lang.IllegalArgumentException
- if the series is invalid.public int getValueLabelStyle()
setValueLabelStyle(int)
public int getValuePosition(double value)
value
- The value to find the position for.
public boolean isAutoLabelSpacingOn()
setAutoLabelSpacingOn(boolean)
public boolean isConnectedLinesOn(int serie)
serie
- The index of the series to check, -1 for all.
setConnectedLinesOn(int, boolean)
public boolean isRightToLeftScrollingOn()
setRightToLeftScrollingOn(boolean)
public boolean isSampleHighlightOn(int series, int sample)
series
- The data series where the sample is.
java.lang.IllegalArgumentException
- if the series or sample is invalid.public boolean isSeriesLineOn(int serie)
serie
- The index of the data series.
java.lang.ArrayIndexOutOfBoundsException
- If the series is invalid.setSeriesLineOn(int, boolean)
public boolean isStackedOn()
setStackedOn(boolean)
public void render(java.awt.Graphics g)
render
in class Chart
g
- The graphics context used to paint with.Chart.paint(java.awt.Graphics)
protected void renderData(java.awt.Graphics g, java.awt.Rectangle grid, java.awt.Rectangle dataBounds)
renderData
in class Chart
g
- The graphics context used to paint with.grid
- The chart grid bounds to paint data within.dataBounds
- The scrolled bounds to calculate the data within.public void reset()
reset
in class Chart
public void setAutoLabelSpacingOn(boolean on)
on
- True for on, false for off.public void setConnectedLinesOn(int serie, boolean on)
serie
- The index of the series, -1 for all.on
- True for on, false for off.public void setLegendImage(int index, java.lang.String name)
setLegendImage
in class Chart
index
- The index of the legend entry to set the image for.name
- The image to use, null for the default legend box.Chart.addImage(java.lang.String, java.awt.Image)
public void setLineWidth(int series, int width)
series
- The series number, -1 for all.width
- The width in pixels, default is 2.public void setRightToLeftScrollingOn(boolean state)
state
- True for on, false for off. Default is off.public void setSampleColors(java.awt.Color[] colors)
setSampleColors
in class Chart
colors
- An array with the colors to be used, null for default colors.public void setSampleHighlightOn(boolean on)
on
- True for on, false for off.public void setSampleHighlightOn(int series, boolean on)
series
- The series to turn highlights on or off for.on
- True for on, false for off.
java.lang.IllegalArgumentException
- if the series is invalid.public void setSampleHighlightOn(int series, int sample, boolean on)
series
- The series where the sample is located.sample
- The sample on that serie to turn on or off.on
- True for on, false for off.
java.lang.IllegalArgumentException
- if the series is invalid.public void setSampleHighlightStyle(int style, int size)
style
- SAMPLE_HIGHLIGHT_CIRCLE, SAMPLE_HIGHLIGHT_CIRCLE_OPAQUE,
SAMPLE_HIGHLIGHT_CIRCLE_FILLED, SAMPLE_HIGHLIGHT_SQUARE,
SAMPLE_HIGHLIGHT_SQUARE_OPAQUE, SAMPLE_HIGHLIGHT_SQUARE_FILLED,
SAMPLE_HIGHLIGHT_DIAMOND, SAMPLE_HIGHLIGHT_DIAMOND_OPAQUE,
SAMPLE_HIGHLIGHT_DIAMOND_FILLED.size
- The size of the circle or square.
java.lang.IllegalArgumentException
- if the type is invalid.
java.lang.IndexOutOfBoundsException
- if the series is invalid.public void setSampleHighlightStyle(int serie, int style, int size)
serie
- The index of the serie.style
- SAMPLE_HIGHLIGHT_CIRCLE, SAMPLE_HIGHLIGHT_CIRCLE_OPAQUE,
SAMPLE_HIGHLIGHT_CIRCLE_FILLED, SAMPLE_HIGHLIGHT_SQUARE,
SAMPLE_HIGHLIGHT_SQUARE_OPAQUE, SAMPLE_HIGHLIGHT_SQUARE_FILLED,
SAMPLE_HIGHLIGHT_DIAMOND, SAMPLE_HIGHLIGHT_DIAMOND_OPAQUE,
SAMPLE_HIGHLIGHT_DIAMOND_FILLED.size
- The size of the circle or square.
java.lang.IndexOutOfBoundsException
- if the series is invalid.public void setSeriesLineOn(boolean state)
state
- True for on (default), false for off.public void setSeriesLineOn(int serie, boolean state)
serie
- The series index.state
- True for on (default), false for off.
java.lang.ArrayIndexOutOfBoundsException
- If the series is invalid.public void setStackedOn(boolean on)
on
- True for on, false for off.public void setValueLabelStyle(int style)
style
- OUTSIDE, INSIDE, FLOATING.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |