AnyLogic 9
Expand
Font size

Pie chart

Pie charts display multiple data items as sectors of a circle, with each sector proportional to its value. Data items cannot be negative. When the total is zero, no sectors are displayed.

A pie chart in AnyLogicPie chart

To create a pie chart

  1. Drag the Icon: Pie chart Pie Chart element from the  Analysis palette into the graphical editor.
  2. In the Data section of the chart’s properties, configure the first data item.
  3. Enter the expression that will be dynamically evaluated to obtain the current value of the data item in the Value box.
  4. Specify the name for the data item in the Title box. This text will be shown in the chart legend.
  5. Specify the color for this data item’s sector. Click the control to use the color picker.

When finished, specify additional data items you want to be displayed in your chart.

To add a data item

By default, a new pie chart already has two data items. To add another, follow these steps:

  1. Select the pie chart in the graphical editor or in the Projects view.
  2. Go to the Data section of the properties.
  3. Click the  Add button. A new property section with settings for one more data item will appear below.

To remove a data item

  1. Select the pie chart in the graphical editor or in the Projects view.
  2. Go to the Data section of the properties.
  3. Locate the section defining the data item you want to remove from the pie chart.
  4. In this section, click the  button.

Properties

General

Name — The name of the chart. The name is used to identify and access the chart from code.

Show name — If selected, the name of the chart is displayed in the presentation diagram.

Lock — If selected, the element is locked; it will not respond to any mouse actions during the model development time. To select the element, click its icon in the Elements view.

Ignore — If selected, the chart is excluded from the model.

Data

Value — The expression which dynamically evaluates the data item value.

Title — The title for this data item which will be shown in the chart legend.

Color — The color that will be used to display this data item value in the chart. Click the control to use the color picker.

The  and  arrows — Allow you to rearrange the data items.

The  button — Allows you to remove data items from the chart.

The  Add button — Creates a section for a new data item.

Data update

Update data automatically — If selected, new data samples will be added automatically.

Use model time —  [Visible if Update data automatically is selected] If selected, the event will occur at the specified model time.

Use calendar date — [Visible if Update data automatically is selected] If selected, the event will occur at the specified calendar date.

First update time — [Visible if Update data automatically and Use model time are selected] The time of the first update defined as a number of model time units that must pass from the model start.

Update date — [Visible if Update data automatically and Use calendar dates are selected] The calendar date and time of the event.

Recurrence time — [Visible if Update data automatically is selected] The time that must pass between recurring updates.

Appearance

Background color — The background color for the entire area allocated for the element. Click the control to adjust it using the color picker. The chart area background color always inherits this setting.

Border color — The color of the outer border of the element. Click the control to adjust it using the color picker.

Position and size

Level — The level this chart belongs to.

X — The X-coordinate of the element’s upper left corner.

Y — The Y-coordinate of the element’s upper left corner.

Width — The width of the element (in pixels).

Height — The height of the element (in pixels).

Legend

Show legend — If selected, the chart legend is displayed.

Position — [Enabled if Show legend is selected] Controls the legend position relative to the chart.

Area size — [Enabled if Show legend is selected] Controls the size of the legend area (between the element border and the divider): width for North/South legend position or height for West/East position.

Text color — [Enabled if Show legend is selected] The color that will be used to display the legend. Click the control to adjust the settings using the color picker.

Chart area

This section defines the visual properties of the chart area.

Border color — The color of the chart area border. To adjust, click the control and use the color picker.

X Offset — The horizontal offset of the chart area from the left edge of the element.

Y Offset — The vertical offset of the chart area from the left edge of the element.

Width — The width of the chart area (in pixels).

Height — The height of the chart area (in pixels).

Actions

On selection change — The code executed when the user selects particular data items. This code is executed either when the user changes the selection by clicking on items in the chart legend, or when the selection is changed programmatically by selectItem().

You can use the following variables:

  • int[] selectedIndices — returns the indices of currently selected data items
  • boolean programmatically — defines whether items were selected programmatically (true) or not (false)
Visibility

Visible — Toggles the visibility of the element. The chart is visible when the box is checked or when the specified expression evaluates to true, and not visible otherwise.

Agent presentation — If selected, the chart is included in the agent presentation. This means that if the agent hosting this control is embedded in another agent, the control will remain visible.

Expert

Replication — The replication factor of the chart. Here you can specify how many copies of the chart will be created. If you leave this box empty, only one chart will be created.

Functions

Data items
Function Description
void addDataItem(DataItem di) Adds a DataItem data item to the chart with the default title and color.

di — the data item to add
void addDataItem(DataItem di, String title, Color color) Adds a data item to the chart.

di — the data item to add
title — the data item title
color — the color to associate with this data item
int getCount() Returns the number of data items currently displayed by this chart.
DataItem get(int i) Returns the chart item (DataItem, DataSet, HistogramData, and so on) with the given index i.

i — the index of the item
String getTitle(int i) Returns the title of the chart item (DataItem, DataSet, etc.) with the given index i.

i — the index of the item
Color getColor(int i) Returns the color of the chart item (DataItem, DataSet) with the given index.

i — the index of the item
void setColor(int i, Color c) Sets the new color of the chart item (DataItem, DataSet) with the given index.

i — the index of the item
c — the new color of the item
void remove(int i) Removes the item (DataItem, DataSet, etc.) with the given index i from the chart.

i — The index of the data element.
int remove(ChartItem ci) Removes the given item ci (DataItem, DataSet) from the chart.

ci — The item to remove.
void removeAll() Removes all items from the chart.
Selecting data items
Function Description
void selectItem(int itemIndex, boolean selected) Selects or deselects (depending on the selected value) the chart item with the given index.

itemIndex — The index of the data element.
select — sets whether to select or deselect the element.
void setSelectedItemIndices(int[] selectedIndices) Selects only the chart items with the given indices.

selectedIndices — an array with indices of the chart items to select (other chart items will be deselected), can be null — this clears the selection
int[] getSelectedItemIndices() Returns the number of data items currently displayed by this chart.
Updating chart data manually
Function Description
void updateData() Updates all data items displayed by this chart.
Location
Function Description
double getX() Returns the X-coordinate of the element (upper left corner).
double getY() Returns the Y-coordinate of the element (upper left corner).
void setX(double x) Sets the X-coordinate of the element.

x  — the new value of the X-coordinate
void setY(double y) Sets the Y-coordinate of the element.

y — the new value of the Y-coordinate
void setPos(double x, double y) Sets new coordinates for the element.

x — the new value of the X-coordinate
y — the new value of the Y-coordinate
Size
Function Description
double getWidth() Returns the width of the element.
double getHeight() Returns the height of the element.
void setWidth(double width) Sets the new width for the chart shape.

width — the new value of the chart width
void setHeight(double height) Sets the new height for the chart shape.

height — the new value of the chart height
Visibility
Function Description
boolean isVisible() Checks the visibility of the element. Returns true if the element is visible, and false otherwise.
void setVisible(boolean v) Sets the visibility of the element.

v — visibility: if true — the chart is set to be visible, if false — not visible.
Copying chart data to clipboard
Function Description
String copyToClipboard()

Copies all chart data to the system clipboard in text form. Returns the text representation of all chart data.

How can we improve this article?