|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.awt.Component java.awt.Container javax.swing.JComponent com.objectplanet.chart.GenericChart com.objectplanet.chart.Chart com.objectplanet.chart.BarChart
public class BarChart
This bar chart component enables you to add a bar chart to your java
applications with just a few lines of code.
A simple bar chart can be created with the following code:
See here for a list of parameters to
set for the bar chart.
BarChart chart = new BarChart(5);
long[] values = new long[] {100, 200, 300, 400, 500};
chart.setSampleValues(values);
A chart with the legend turned on, multicolor set, and displayed in 3D can be
created with the following code:
BarChart chart = new BarChart(5);
long[] values = new long[] {100, 200, 300, 400, 500};
chart.setSampleValues(values);
chart.setMultiColorOn(true);
chart.setLegendOn(true);
chart.set3DModeOn(true);
Nested Class Summary |
---|
Nested classes/interfaces inherited from class javax.swing.JComponent |
---|
javax.swing.JComponent.AccessibleJComponent |
Nested classes/interfaces inherited from class java.awt.Container |
---|
java.awt.Container.AccessibleAWTContainer |
Nested classes/interfaces inherited from class java.awt.Component |
---|
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy |
Field Summary | |
---|---|
static int |
BEHIND_BARS
Use bars behind each other in multiple series charts; setBarType() |
static int |
BLOCK
|
static int |
CYLINDER
|
static int |
SIDE_BY_SIDE_BARS
Use side-by-side bars in multiple series charts; setBarType() |
static int |
STACKED_BARS
Use stacked bars in multiple series charts; setBarType() |
Fields inherited from class com.objectplanet.chart.Chart |
---|
BELOW, BELOW_AND_FLOATING, BOTTOM, chartData, FLOATING, HORIZONTAL, INSIDE, LEFT, OUTSIDE, POINTING, RIGHT, 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 com.objectplanet.chart.GenericChart |
---|
chartType, DEFAULT_SAMPLE_COLORS, depth3dPoint, display3dOn, displayVersionOn, dragged_label, grid, gridRenderer, legend, legendRenderer, legendSelection, needChartCalculation, needGraphBounds, needRender, new_cursor, old_cursor, overlayCharts, renderer |
Fields inherited from class javax.swing.JComponent |
---|
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW |
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 | |
---|---|
BarChart()
Creates a bar chart with 1 series, 1 sample and a range of 100. |
|
BarChart(int count)
Creates a bar chart with the given number of samples and default range. |
|
BarChart(int count,
double range)
Creates a bar chart with the given number of bars and range. |
|
BarChart(int sampleCount,
double range,
double lowerRange)
Creates a bar chart with the given number of bars and range. |
|
BarChart(int seriesCount,
int sampleCount,
double range,
double lowerRange)
Creates a bar chart with the given number of series and bars and range. |
Method Summary | |
---|---|
protected void |
checkDataIntegrity()
Makes sure the barchart specific data has the same number of series and samples as the chart data has. |
ChartSample |
checkSelection(java.awt.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. |
java.awt.Rectangle |
getBarBounds(int serie,
int sample)
Gets the bounds of the specified bar. |
java.awt.Color |
getBarLabelColor(int index)
Gets the color of the bar label of the specified sample. |
java.lang.String[] |
getBarLabels()
Gets the bar labels. |
java.awt.Color |
getBarOutlineColor()
Gets the color used for the bar outline. |
int |
getBarShape()
|
int |
getBarType()
Gets the current bar type in multiple series charts. |
double |
getBarWidth()
Gets the relative width of each bar. |
int |
getGridAlignment()
Gets the bar alignment. |
protected double |
getHighestValue(int range)
Gets the highest value in the chart larger than 0. |
java.lang.String[] |
getLegendLabels()
Gets the legend labels. |
protected double |
getLowestValue(int range)
Gets the value of the deepest bar, stacked or not. |
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 |
isBarLabelsOn()
Checks if the bar labels are turned on. |
boolean |
isBarOutlineOn()
Checks if the bar outline is turned on or off. |
boolean |
isMultiColorOn()
Checks if the multicolor mode is turned on. |
boolean |
isMultiSeriesOn()
Checks if the chart is in multi series mode. |
void |
reset()
Resets the chart data and features. |
void |
setAutoLabelSpacingOn(boolean on)
Turns on or off automatic bar label spacing. |
void |
setBarAlignment(int alignment)
Sets the bar alignment. |
void |
setBarLabelColor(int index,
java.awt.Color color)
Sets the color of of the bar label for the specified sample. |
void |
setBarLabels(java.lang.String[] labels)
Sets the bar labels. |
void |
setBarLabelsOn(boolean on)
Turns on or off the bar labels. |
void |
setBarOutlineColor(java.awt.Color color)
Sets the color used for the bar outline. |
void |
setBarOutlineOn(boolean on)
Turns on or off the bar outline. |
void |
setBarShape(int shape)
|
void |
setBarType(int type)
Sets the bar type in multiple series charts. |
void |
setBarWidth(double width)
Sets the relative width of each bar. |
void |
setMultiColorOn(boolean on)
Turns on or off multi-color bar display. |
void |
setMultiSeriesOn(boolean state)
Makes the chart behave like it does when it has multiple data series, even if it has only one. |
Methods inherited from class javax.swing.JComponent |
---|
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getAccessibleContext, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getNextFocusableComponent, getPopupLocation, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, paramString, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, updateUI |
Methods inherited from class java.awt.Container |
---|
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusBackward, transferFocusDownCycle, validate, validateTree |
Methods inherited from class java.awt.Component |
---|
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocation, setLocation, setName, setSize, setSize, show, show, size, transferFocus, transferFocusUpCycle |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final int BEHIND_BARS
public static final int BLOCK
public static final int CYLINDER
public static final int SIDE_BY_SIDE_BARS
public static final int STACKED_BARS
Constructor Detail |
---|
public BarChart()
public BarChart(int count)
count
- The number of bars for the chart.public BarChart(int count, double range)
count
- The number of bars for the chart.range
- The initial range of the chart.public BarChart(int sampleCount, double range, double lowerRange)
sampleCount
- The number of bars for the chart.range
- The initial upper range of the chart.lowerRange
- The initial lower range of the chart.public BarChart(int seriesCount, int sampleCount, double range, double lowerRange)
seriesCount
- The number of data series in the chart.sampleCount
- The number of sample in the chart.range
- The initial upper range of the chart.lowerRange
- The initial lower range of the chart.Method Detail |
---|
protected void checkDataIntegrity()
checkDataIntegrity
in class Chart
public ChartSample checkSelection(java.awt.Point point)
checkSelection
in class Chart
point
- The point clicked on.
public java.awt.Rectangle getBarBounds(int serie, int sample)
serie
- The series indexsample
- The sample index.
public java.awt.Color getBarLabelColor(int index)
index
- The index of the sample (0-based).
java.lang.IllegalArgumentException
- if the sample index is invalid.public java.lang.String[] getBarLabels()
public java.awt.Color getBarOutlineColor()
public int getBarShape()
public int getBarType()
public double getBarWidth()
setBarWidth(double)
public int getGridAlignment()
setBarAlignment(int)
protected double getHighestValue(int range)
getHighestValue
in class Chart
range
- The index of the range (0 or 1).
public java.lang.String[] getLegendLabels()
getLegendLabels
in class Chart
GenericChart.setLegendLabels(java.lang.String[])
protected double getLowestValue(int range)
getLowestValue
in class Chart
range
- The index of the range (0 or 1).public int getValuePosition(double value)
value
- The value to find the position for.
public boolean isAutoLabelSpacingOn()
setAutoLabelSpacingOn(boolean)
public boolean isBarLabelsOn()
public boolean isBarOutlineOn()
public boolean isMultiColorOn()
public boolean isMultiSeriesOn()
isMultiSeriesOn
in class GenericChart
setMultiSeriesOn(boolean)
public void reset()
reset
in class Chart
public void setAutoLabelSpacingOn(boolean on)
on
- True for on, false for off.public void setBarAlignment(int alignment)
alignment
- HORIZONTAL or VERTICAL.
java.lang.IllegalArgumentException
- If the alignment is not valid.public void setBarLabelColor(int index, java.awt.Color color)
index
- The index of the sample (0-based).color
- The color to use, null for the samleColors color.
java.lang.IllegalArgumentException
- if the sample index is invalid.public void setBarLabels(java.lang.String[] labels)
labels
- The labels, or null for default behavior.setBarLabelsOn(boolean)
,
Chart.setSampleLabels(java.lang.String[])
public void setBarLabelsOn(boolean on)
on
- True if the bar labels should be displayed.Chart.setSampleLabel(int, java.lang.String)
public void setBarOutlineColor(java.awt.Color color)
color
- The color to set.public void setBarOutlineOn(boolean on)
on
- True if on, false for off.public void setBarShape(int shape)
public void setBarType(int type)
type
- STACKED_BARS, SIDE_BY_SIDE_BARS or BEHIND_BARS.
java.lang.IllegalArgumentException
- If the type is not valid.public void setBarWidth(double width)
width
- The width fraction to use (0.0 to 1.0).public void setMultiColorOn(boolean on)
on
- True for multi-color, false for single-color.public void setMultiSeriesOn(boolean state)
setMultiSeriesOn
in class GenericChart
state
- True for on, false for off.
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |