AnyLogic
Expand
Font size
All Implemented Interfaces:
com.anylogic.engine.internal.Child, Locatable2D, AggregatableAnimationElement, HasLevel, LevelElement, SVGElement, java.io.Serializable, java.lang.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

Nested Classes 
static class  Chart.Direction
multipurpose direction/position constants
static class  Chart.GridPosition
grid text position constants
static class  Chart.InterpolationType
interpolation types
static class  Chart.PointStyle
line point styles
static class  Chart.ScaleType
scale types
static class  Chart.TimeWindowMovementType  
Modifier and Type Class Description

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

ShapeControl.ValueType

Field Summary

Fields 
static java.lang.String DEFAULT_DATE_PATTERN  
static java.lang.String DEFAULT_DATE_TIME_PATTERN  
static java.lang.String DEFAULT_TIME_PATTERN  
static Chart.Direction EAST  
static Chart.GridPosition GRID_DEFAULT  
static Chart.GridPosition GRID_NONE  
static Chart.GridPosition GRID_OPPOSITE  
static Chart.InterpolationType INTERPOLATION_LINEAR  
static Chart.InterpolationType INTERPOLATION_STEP  
static Chart.Direction NONE  
static Chart.Direction NORTH  
static Chart.PointStyle POINT_CIRCLE  
static Chart.PointStyle POINT_NONE  
static Chart.PointStyle POINT_SQUARE  
static Chart.PointStyle POINT_TRIANGLE  
static Chart.ScaleType SCALE_100_PERCENT  
static Chart.ScaleType SCALE_AUTO  
static Chart.ScaleType SCALE_AUTO_FROM_0  
static Chart.ScaleType SCALE_FIXED  
static java.lang.String SHORT_DATE_PATTERN  
static java.lang.String SHORT_DATE_TIME_PATTERN  
static java.lang.String SHORT_TIME_PATTERN  
static Chart.Direction SOUTH  
static Chart.Direction WEST  
static Chart.TimeWindowMovementType WINDOW_MOVES_WITH_DATA  
static Chart.TimeWindowMovementType WINDOW_MOVES_WITH_TIME  
Modifier and Type Field Description

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

Constructor Summary

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

Method Summary

All Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods 
void action()
Does nothing: no actions are associated with charts.
Shape clone()
Cloning of charts is not supported
(Other shapes except GIS and controls allow cloning)
This method throws UnsupportedOperationException if called
java.lang.String copyToClipboard()
Deprecated.
will be removed in the future release.
void executeUserAction​(java.lang.String value)
This method is internal and shouldn't be called by user.
it may be removed/renamed in future.
E get​(int i)
Returns the chart item (DataItem, DataSet, HistogramData, etc.) with the given index.
abstract java.awt.Color getColor​(int i)
Returns the color of the chart item with the given index.
int getCount()
Returns the number of chart items (data items or data sets) currently displayed by this chart.
javax.swing.JComponent getJComponent()
Deprecated.
This function is deprecated and will be removed in the next release
int[] getSelectedItemIndices()
Returns an array with indices of selected chart items
java.lang.String getTitle​(int i)
Returns the title of chart item (DataItem, DataSet, HistogramData, etc.) with the given index.
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.
void postSVGShapeSpecificAttributes​(java.util.List<java.lang.String> att, java.util.List<java.lang.String> val, boolean publicOnly)
Posts general properties specific to a particular shape class.
void refresh()
Deprecated.
void remove​(int i)
Removes the item (DataItem, DataSet, HistogramData, etc.) with the given index from the chart.
int remove​(ChartItem ci)
Removes the given item (DataItem, DataSet, HistogramData, Histogram2DData) from the chart.
void removeAll()
Removes all items from the chart.
void selectItem​(int itemIndex, boolean selected)
Selects/deselects (depending on selected value) chart item with given index
void setColor​(int i, java.awt.Color c)
Sets the new color of the chart item with the given index.
void setSelectedItemIndices​(int[] selectedIndices)
Selects only chart items with given indices
void update()
Deprecated.
This method is internal and shouldn't be called by user.
it may be removed/renamed in future.
void updateData()
Updates all data items / data sets displayed by this chart.
Modifier and Type Method Description

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 com.anylogic.engine.presentation.Shape

canHandleClick, findSVGElement, getDrawMode, getGroup, getLevel, getName, getRotation, getScaleX, getScaleY, getSVGId, getX, getY, isJava2DSwingPresentation, isPublic_xjal, isSVGPresentation, isVisible, onAggregatorVisibilityChanged, onClick, randomPointInside, removeSVGFromOwner, removeSVGImage, resetSVGState, setLevel, setPos, setPos, setPublic_xjal, setRotation, setScale, setScale, setScaleX, setScaleY, setVisible, setX, setY, updateDynamicProperties, updateDynamicPropertiesStructural, updateSVGProperties

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 Detail

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 java.lang.String DEFAULT_TIME_PATTERN

DEFAULT_DATE_PATTERN

public static final java.lang.String DEFAULT_DATE_PATTERN

DEFAULT_DATE_TIME_PATTERN

public static final java.lang.String DEFAULT_DATE_TIME_PATTERN

SHORT_TIME_PATTERN

public static final java.lang.String SHORT_TIME_PATTERN

SHORT_DATE_PATTERN

public static final java.lang.String SHORT_DATE_PATTERN

SHORT_DATE_TIME_PATTERN

public static final java.lang.String SHORT_DATE_TIME_PATTERN

Constructor Detail

Chart

public Chart​(Presentable p,
             boolean ispublic,
             double x,
             double y,
             double width,
             double height,
             java.awt.Color fillColor,
             java.awt.Color lineColor,
             double picOffsetX,
             double picOffsetY,
             double picWidth,
             double picHeight,
             java.awt.Color picBackgoundColor,
             java.awt.Color picBorderColor,
             java.awt.Color legendTextColor,
             double legendSize,
             Chart.Direction legendPos,
             java.util.List<java.lang.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 Detail

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 java.lang.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,
                     java.awt.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 java.awt.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 java.lang.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 javax.swing.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​(java.util.List<java.lang.String> att,
                                           java.util.List<java.lang.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​(java.lang.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
How can we improve this article?