Use Any Chart
Introduction
The basic charts provide a set of easy to configure charts such as line, bar, column, pie, and so forth. These charts can be fine tuned with the advanced options.
When the advanced options are not enough, the Any Chart widget can be used.
With Any Chart you can build all the chart types that are possible with Plotly.js as well as options for configuring charts dynamically. So, if you want to build a 3D chart or have a dynamic set of series, Any Chart is your friend.
This how-to teaches you how to do the following:
- Create a line chart with sample data
- Export data for a chart
- Fine tune the chart with the run-time playground
Prerequisites
Before starting this how-to, make sure you have the following prerequisites:
- The latest version of Mendix Studio Pro
- The latest Any Chart module
- An understanding of JSON data structures
Chart Structure
An Any Chart widget can be configured with a JSON Data array and Layout object. The configuration can be set statically, via the Source attribute or with the Sample data.
The configuration in the Source attribute will be merged into the static settings and will overwrite any common properties. The Sample data is for demo purposes at run time when there is no Source attribute selected or when rendering sample data in the Studio Pro preview.
Creating a Chart
To create a line chart with the Any Chart widget, follow these steps:
-
Create a page with a data view (Chart context).
-
Add the Any Chart widget in the data view.
-
Select the line chart sample from the Any Chart cheat sheet:
[ { "x": [ 1, 2 ], "y": [ 1, 2 ], "type": "scatter" } ]
-
In Studio Pro, copy the data into the Any Chart widget property tab Data, field Static.
-
Run the app to confirm the chart renders correctly.
-
Split the data into static and dynamic parts that are going to be generated from the domain model.
Static :
[ { "type": "scatter" } ]
Sample data :
[ { "x": [ 1, 2 ], "y": [ 1, 2 ] } ]
-
Run the app to preview the chart.
Exporting Data
To generate JSON data for the Charts widget, follow these steps:
- Add a Data string (unlimited length) attribute to the Chart (context) entity.
- In the widget, set the Source attribute field in the Data tab.
- Create a JSON Structure and use the Sample data as the snippet.
- Create an Export Mapping with the JSON Structure.
- Create a microflow that retrieves the data.
- Use the Export Mapping to generate a String Variable. Store the value in the object attribute that is selected as Source attribute.
If need be, the layout can also be generated in the same way as the data. In most cases, a Static layout will suffice.
Fine tuning
Editing the JSON configuration in Studio Pro can be cumbersome. With the live preview editor, developers can directly see the output of their changes.
To fine tune a Charts widget configuration, follow these steps:
-
In the Data tab, set the Mode option to Development.
-
Run the app, and open the page containing the chart.
-
Click the Toggle Editor button on the top right of the chart to fine-tune your settings.
-
In the editor, select either Data or Layout from the drop-down menu.
-
Edit Static or Data settings.
-
Copy the new settings and apply them in Studio Pro.
-
Re-run the app to confirm the changes have been applied.
Read More
- Any Chart properties: Any Chart
- The most common chart types: Any Chart Cheat Sheet
- The most common settings: Configuration Cheat Sheet
- The full JSON reference: https://plot.ly/javascript/reference/
- JSON Structures
- Export Mappings