If you would like to upgrade to a newer long-term support version of Studio Pro, see Moving from Mendix Studio Pro 8 to 9.
Create a Dynamic Series Chart
Introduction
The charts widget provides a basic implementation of dynamic series. This allows you to vary the number of data series (for example lines on a line chart) in your chart at runtime, based on the data in your app.
This how-to teaches you how to do the following:
- Create a chart with dynamic series
Prerequisites
Before starting this how-to, make sure you have completed the following prerequisites:
- Download the latest Charts Widget from the Mendix Marketplace
Setting up Chart Data
Setting up the Domain Model
In order to create the Charts widget with dynamic series, a specific data structure is set up.
- Configure your domain model to contain an entity Value with attributes xValue and yValue.
- Add another entity, Series, with attributes name, color, and fillColor.
- Add an association Value_Series between the two entities.
Entering Data for the Chart
Now you need to enter data for the chart.
-
Right-click the Series entity.
-
Choose Generate overview pages….
-
Select both Series and Value as the entities for which to generate pages.
-
Connect the Series_Overview page to the navigation.
-
Run the app (locally).
-
Enter some sample data.
Configuring the Charts Widget
Adding a Chart Page
Now you need to create a page containing the chart.
- Create a new page.
- Add a data view which uses a microflow to make a context which is the first object of the Value.
- Add an Area chart widget inside the data view.
Configuring the Area Chart with Dynamic Series
To configure a Charts widget with a dynamic series, follow these steps:
-
Right-click the area chart widget and select Properties.
-
In the tab Chart properties, add a new Series property.
-
In the tab Data source, select Dynamic.
-
Set the Data entity to Value. This is the entity from which the data values will be retrieved.
-
Set the Data source as Database (note that REST endpoints are not supported for dynamic series).
-
In the tab Data Points, set:
- X-axis data attribute to Value/xValue
- Y-axis data attribute to Value/yValue
-
In the tab Dynamic series, set:
- Series entity to Series
- Series name attribute to Series/name
- Line color attribute to Series/color
- Area color attribute to Series/fillcolor
-
Add the charts page to user navigation.
Viewing the Chart
To view the chart, follow these steps:
-
Run the app (locally).
-
Open the page containing the dynamic series chart.