AnyLogic
Expand
Font size
All Implemented Interfaces:
com.anylogic.engine.internal.Child, Locatable2D, AggregatableAnimationElement, HasLevel, LevelElement, SVGElement, UsdElement, Serializable, Cloneable
Direct Known Subclasses:
Chart1D, Chart2D, Histogram, Histogram2D

public abstract class Chart<E extends ChartItem>
extends ShapeControl
The base class for all charts. Embeds JPanel with several sub-components. Is responsible for the chart overall layout, and for the chart legend functionality. Delegates the drawing of the chart to its subclasses.
The chart area is divided into two parts: the picture area (where the picture, like plot, pie, bar, histogram, etc. is drawn) and the legend area. The legend can be located on either of the four sides of the chart (NORTH, SOUTH, EAST, WEST), or absent (NONE). The picture can be located at arbitrary position within the picture area, i.e. the part of the chart not occupied by the legend.
Author:
AnyLogic North America, LLC https://anylogic.com
See Also:
Serialized Form

Nested Class Summary

Modifier and TypeClassDescription
static enum Chart.Direction
multipurpose direction/position constants
static enum Chart.GridPosition
grid text position constants
static enum Chart.InterpolationType
interpolation types
static enum Chart.PointStyle
line point styles
static enum Chart.ScaleType
scale types
static enum Chart.TimeWindowMovementType 

Nested classes/interfaces inherited from class com.anylogic.engine.presentation.ShapeControl

ShapeControl.ValueType

Field Summary

Modifier and TypeFieldDescription
static final StringDEFAULT_DATE_PATTERN 
static final StringDEFAULT_DATE_TIME_PATTERN 
static final StringDEFAULT_TIME_PATTERN 
static final Chart.DirectionEAST 
static final Chart.GridPositionGRID_DEFAULT 
static final Chart.GridPositionGRID_NONE 
static final Chart.GridPositionGRID_OPPOSITE 
static final Chart.InterpolationTypeINTERPOLATION_LINEAR 
static final Chart.InterpolationTypeINTERPOLATION_STEP 
static final Chart.DirectionNONE 
static final Chart.DirectionNORTH 
static final Chart.PointStylePOINT_CIRCLE 
static final Chart.PointStylePOINT_NONE 
static final Chart.PointStylePOINT_SQUARE 
static final Chart.PointStylePOINT_TRIANGLE 
static final Chart.ScaleTypeSCALE_100_PERCENT 
static final Chart.ScaleTypeSCALE_AUTO 
static final Chart.ScaleTypeSCALE_AUTO_FROM_0 
static final Chart.ScaleTypeSCALE_FIXED 
static final StringSHORT_DATE_PATTERN 
static final StringSHORT_DATE_TIME_PATTERN 
static final StringSHORT_TIME_PATTERN 
static final Chart.DirectionSOUTH 
static final Chart.DirectionWEST 
static final Chart.TimeWindowMovementTypeWINDOW_MOVES_WITH_DATA 
static final Chart.TimeWindowMovementTypeWINDOW_MOVES_WITH_TIME 

Fields inherited from class com.anylogic.engine.presentation.ShapeControl

TYPE_DOUBLE, TYPE_INT, TYPE_STRING

Fields inherited from class com.anylogic.engine.presentation.Shape

UNKNOWN_NAME

Fields inherited from interface com.anylogic.engine.presentation.UsdElement

ID_NOT_SET

Constructor Summary

ConstructorDescription
Chart(Presentable p, boolean ispublic, double x, double y, double width, double height, Color fillColor, Color lineColor, double picOffsetX, double picOffsetY, double picWidth, double picHeight, Color picBackgoundColor, Color picBorderColor, Color legendTextColor, double legendSize, Chart.Direction legendPos, List<String> titles)
Creates a persistent chart.

Method Summary

Modifier and TypeMethodDescription
voidaction()
Does nothing: no actions are associated with charts.
final Shapeclone()
Cloning of charts is not supported
(Other shapes except GIS and controls allow cloning)
This method throws UnsupportedOperationException if called
StringcopyToClipboard()
Deprecated.
will be removed in the future release.
voidexecuteUserAction(String value)
This method is internal and shouldn't be called by user.
it may be removed/renamed in future.
final Eget(int i)
Returns the chart item (DataItem, DataSet, HistogramData, etc.) with the given index.
abstract ColorgetColor(int i)
Returns the color of the chart item with the given index.
final intgetCount()
Returns the number of chart items (data items or data sets) currently displayed by this chart.
JComponentgetJComponent()
Deprecated.
This function is deprecated and will be removed in the next release
int[]getSelectedItemIndices()
Returns an array with indices of selected chart items
final StringgetTitle(int i)
Returns the title of chart item (DataItem, DataSet, HistogramData, etc.) with the given index.
voidonSelectionChanged_xjal(int[] selectedIndices, boolean programmatically)
Executes specific action when user clicks on legend and selects/deselects chart item(s).
This method does nothing by default and may be overridden for charts they have any on-selection-changed activity.
voidpostSVGShapeSpecificAttributes(List<String> att, List<String> val, boolean publicOnly)
Posts general properties specific to a particular shape class.
voidrefresh()
Deprecated.
final voidremove(int i)
Removes the item (DataItem, DataSet, HistogramData, etc.) with the given index from the chart.
final intremove(ChartItem ci)
Removes the given item (DataItem, DataSet, HistogramData, Histogram2DData) from the chart.
voidremoveAll()
Removes all items from the chart.
voidselectItem(int itemIndex, boolean selected)
Selects/deselects (depending on selected value) chart item with given index
voidsetColor(int i, Color c)
Sets the new color of the chart item with the given index.
voidsetSelectedItemIndices(int[] selectedIndices)
Selects only chart items with given indices
voidupdate()
Deprecated.
This method is internal and shouldn't be called by user.
it may be removed/renamed in future.
voidupdateData()
Updates all data items / data sets displayed by this chart.

Methods inherited from class com.anylogic.engine.presentation.ShapeControl

contains, executeAction, getHeight, getPresentable, getWidth, isEnabled, randomPointInside, restoreOwner, setEnabled, setHeight, setValueToDefault, setWidth

Methods inherited from class java.lang.Object

equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Methods inherited from interface com.anylogic.engine.markup.AggregatableAnimationElement

initializeInternal, postInitialize

Field Details

NONE

public static final Chart.Direction NONE

SOUTH

public static final Chart.Direction SOUTH

WEST

public static final Chart.Direction WEST

EAST

public static final Chart.Direction EAST

NORTH

public static final Chart.Direction NORTH

GRID_NONE

public static final Chart.GridPosition GRID_NONE

GRID_DEFAULT

public static final Chart.GridPosition GRID_DEFAULT

GRID_OPPOSITE

public static final Chart.GridPosition GRID_OPPOSITE

SCALE_AUTO

public static final Chart.ScaleType SCALE_AUTO

SCALE_AUTO_FROM_0

public static final Chart.ScaleType SCALE_AUTO_FROM_0

SCALE_FIXED

public static final Chart.ScaleType SCALE_FIXED

SCALE_100_PERCENT

public static final Chart.ScaleType SCALE_100_PERCENT

POINT_NONE

public static final Chart.PointStyle POINT_NONE

POINT_SQUARE

public static final Chart.PointStyle POINT_SQUARE

POINT_CIRCLE

public static final Chart.PointStyle POINT_CIRCLE

POINT_TRIANGLE

public static final Chart.PointStyle POINT_TRIANGLE

INTERPOLATION_STEP

public static final Chart.InterpolationType INTERPOLATION_STEP

INTERPOLATION_LINEAR

public static final Chart.InterpolationType INTERPOLATION_LINEAR

WINDOW_MOVES_WITH_TIME

public static final Chart.TimeWindowMovementType WINDOW_MOVES_WITH_TIME

WINDOW_MOVES_WITH_DATA

public static final Chart.TimeWindowMovementType WINDOW_MOVES_WITH_DATA

DEFAULT_TIME_PATTERN

public static final String DEFAULT_TIME_PATTERN

DEFAULT_DATE_PATTERN

public static final String DEFAULT_DATE_PATTERN

DEFAULT_DATE_TIME_PATTERN

public static final String DEFAULT_DATE_TIME_PATTERN

SHORT_TIME_PATTERN

public static final String SHORT_TIME_PATTERN

SHORT_DATE_PATTERN

public static final String SHORT_DATE_PATTERN

SHORT_DATE_TIME_PATTERN

public static final String SHORT_DATE_TIME_PATTERN

Constructor Details

Chart

public Chart(Presentable p,
 boolean ispublic,
 double x,
 double y,
 double width,
 double height,
 Color fillColor,
 Color lineColor,
 double picOffsetX,
 double picOffsetY,
 double picWidth,
 double picHeight,
 Color picBackgoundColor,
 Color picBorderColor,
 Color legendTextColor,
 double legendSize,
 Chart.Direction legendPos,
 List<String> titles)
Creates a persistent chart.
Parameters:
p - the presentable object owning this chart
ispublic - if true, the chart is visible on container's presentation
x - the x coordinate of the chart
y - the y coordinate of the chart
width - the width of the whole chart
height - the height of the whole chart
fillColor - the background color of the whole chart
lineColor - the line border color of the whole chart
picOffsetX - the x offset of the picture from the top left corner of the picture area
picOffsetY - the y offset of the picture from the top left corner of the picture area
picWidth - the width of the picture
picHeight - the height of the picture
picBackgoundColor - the background color of the picture, null for none (transparent)
picBorderColor - the border color of the picture, null for no border
legendTextColor - the color of the legend text
legendSize - the size of the legend area: width if legendPos is EAST or WEST, height if NORTH or SOUTH
legendPos - the legend position (NONE, SOUTH, NORTH, EAST, WEST)
titles - the collection of chart item titles, or null

Method Details

refresh

@Deprecated
public void refresh()
Deprecated.
Causes the chart to refresh its picture and legend based on the current data values and schedules the component repaint. This method needs to be extended in subclasses by doing some work before calling super.refresh()

getCount

public final int getCount()
Returns the number of chart items (data items or data sets) currently displayed by this chart.
Returns:
the number of chart items

get

public final E get(int i)
Returns the chart item (DataItem, DataSet, HistogramData, etc.) with the given index.
Parameters:
i - index of the item
Returns:
the chart item with the given index

getTitle

public final String getTitle(int i)
Returns the title of chart item (DataItem, DataSet, HistogramData, etc.) with the given index.
Parameters:
i - index of the item
Returns:
the title of the chart item with the given index

setColor

public void setColor(int i,
 Color c)
Sets the new color of the chart item with the given index. The effect depends on the chart type.
Parameters:
i - index of the item
c - the new color of the item
Since:
8.5

getColor

public abstract Color getColor(int i)
Returns the color of the chart item with the given index. it depends on the chart type, which color exactly is returned.
Parameters:
i - index of the item
Returns:
the color of the item

remove

public final int remove(ChartItem ci)
Removes the given item (DataItem, DataSet, HistogramData, Histogram2DData) from the chart. If the item is not present, does nothing.
Parameters:
ci - the chart item to remove
Returns:
the index of the item

remove

public final void remove(int i)
Removes the item (DataItem, DataSet, HistogramData, etc.) with the given index from the chart.
Parameters:
i - the index of item to remove

removeAll

public void removeAll()
Removes all items from the chart.

updateData

public void updateData()
Updates all data items / data sets displayed by this chart. In contrast with update(), this method only updates the data, but does not update the chart visual appearance.

copyToClipboard

@Deprecated
public String copyToClipboard()
Deprecated.
will be removed in the future release. Please use copy button on model animation or Utilities.copyToClipboard(String).

update

@AnyLogicInternalAPI
@Deprecated
public void update()
Deprecated.
This method is internal and shouldn't be called by user.
it may be removed/renamed in future.

action

@AnyLogicInternalAPI
public void action()
Does nothing: no actions are associated with charts.
Overrides:
action in class ShapeControl

getJComponent

@Deprecated
public JComponent getJComponent()
Deprecated.
This function is deprecated and will be removed in the next release
Returns the embedded JPanel.

clone

public final Shape clone()
Cloning of charts is not supported
(Other shapes except GIS and controls allow cloning)
This method throws UnsupportedOperationException if called
Overrides:
clone in class ShapeControl

getSelectedItemIndices

public int[] getSelectedItemIndices()
Returns an array with indices of selected chart items
Returns:
an array with indices of selected chart items

setSelectedItemIndices

public void setSelectedItemIndices(int[] selectedIndices)
Selects only chart items with given indices
Parameters:
selectedIndices - an array with indices of chart items to be selected (other chart items will be deselected), may be null - this clears selection

selectItem

public void selectItem(int itemIndex,
 boolean selected)
Selects/deselects (depending on selected value) chart item with given index
Parameters:
itemIndex - the index of chart item shown on the chart
selected - whether select this chart item or deselect it

onSelectionChanged_xjal

@AnyLogicInternalCodegenAPI
public void onSelectionChanged_xjal(int[] selectedIndices,
 boolean programmatically)
Executes specific action when user clicks on legend and selects/deselects chart item(s).
This method does nothing by default and may be overridden for charts they have any on-selection-changed activity.
Parameters:
selectedIndices - the array of currently selected indices (never null; may be empty)
programmatically - defines either selection was changed programmatically (via selectItem(int, boolean) and setSelectedItemIndices(int[])) or by user mouse-click

postSVGShapeSpecificAttributes

public void postSVGShapeSpecificAttributes(List<String> att,
 List<String> val,
 boolean publicOnly)
Description copied from class: Shape
Posts general properties specific to a particular shape class. Is triggered by SVG_DIRTY_SHAPE flag. Made public for occasional posting of additional SVG properties from outside engine (e.g. from libraries)
Overrides:
postSVGShapeSpecificAttributes in class ShapeControl
Parameters:
att - attribute names
val - attribute values
publicOnly - TODO

executeUserAction

@AnyLogicInternalAPI
public void executeUserAction(String value)
Description copied from interface: SVGElement
This method is internal and shouldn't be called by user.
it may be removed/renamed in future.
Specified by:
executeUserAction in interface SVGElement
Overrides:
executeUserAction in class Shape