Use the Charts Theme
Introduction
You can fine-tune the look of individual Charts widgets with their advanced settings. A theme file lets you create global settings that apply to all charts in an app. In this way, you can set colors, language, fonts, and many other things for all charts at once.
This how-to teaches you how to do the following:
- Find the settings you want with the Chart playground
- Add a theme configuration file
- Change the font for all charts
Prerequisites
Before starting this how-to, make sure you have completed the following prerequisites:
- Download the latest Charts module from the Mendix Marketplace
- Set up a chart by following Create a Basic Chart
Creating a Chart Theme
This is how the original chart looks:
Finding the Settings with Chart Playground
To find the settings you want, follow these steps:
-
Add a Chart playground to your chart, as described in Opening the Playground.
-
Run the app and open the page with the chart in the browser.
-
Click Toggle Editor.
-
In the drop-down list, select Layout, and add the following JSON to Custom settings:
{ "font": { "family": "Open Sans", "size": 14, "color": "#555" } } -
Change the font settings until the chart shows the font you want, then copy the JSON.
Changes made in the playground do not persist. Store them in the advanced settings of the widget or in the theme file. -
In Studio Pro, remove the Chart playground from the chart, as described in Removing the Playground.
Adding a Theme Configuration
To add a theme file that applies to all charts in the app, follow these steps:
-
In Studio Pro, go to App > Show App Directory in Explorer (or Show App Directory in Finder on macOS).
-
Open the [YOUR-APP]/theme/web folder (or [YOUR-APP]/theme/native if using native apps).
-
Create a new file named com.mendix.charts.json:
The file name is case-sensitive, and the file extension is .json. The file must contain a JSON object, even if it is empty, for example{ }. -
For each chart that should use the theme, open the chart properties, set Enable advanced options to Yes on the General tab, then go to the Advanced tab and set Enable theme folder config loading to Yes:
Charts that have Enable theme folder config loading set to No ignore the theme file.
Changing the Font Globally
To change the font in all charts in the app, follow these steps:
-
Open the [app folder]/theme/web/com.mendix.charts.json file in a plain text editor.
-
Replace or update the content. In the
layoutsection, place the font settings that you found in the playground:{ "layout": { "font": { "family": "Impact", "size": 20, "color": "#4682B4" } } } -
Restart the Mendix app.
-
Check the result:
Theme File Structure
The theme file can contain three top-level properties. At least one of them must be present; otherwise, the file is ignored and a warning is logged in the browser console.
layout– Layout settings applied to all charts. For available options, see Layout in the Plotly documentation.configuration– Configuration settings applied to all charts. For available options, see Configuration Options in the Plotly documentation.charts– Series settings per chart type. Each key is a chart type, and its value is applied to every series of that chart type. For available options, see the JavaScript Figure Reference in the Plotly documentation. The possible keys areAreaChart,BarChart,BubbleChart,ColumnChart,HeatMap,LineChart,PieChart, andTimeSeries.
This is an example of a theme file:
{
"layout": {
"font": {
"family": "Open Sans",
"size": 14
}
},
"configuration": {
"displayModeBar": false
},
"charts": {
"LineChart": {
"line": {
"width": 3
}
},
"BarChart": {
"opacity": 0.8
}
}
}