Themes
Themes in amCharts 4 is much more than just collection of appearance settings. They can change the way chart acts, looks, and even modify and create chart objects. Plus, you can apply several themes to a single chart!
Using themes
Section titled “Using themes”A theme is not an ordinary chart’s setting. It’s a system-wide setting which is applied to all the charts that are created.
Loading a theme
Section titled “Loading a theme”Before a theme can be applied, it needs to be loaded, just like any other resource:
// ... other importsimport am4themes_animated from "@amcharts/amcharts4/themes/animated";<script src="//www.amcharts.com/lib/4/themes/animated.js"></script>Applying a theme
Section titled “Applying a theme”As mentioned before, a theme is not applied directly to a chart object, but rather to the whole system, which affects all charts that are created afterwards.
To apply a theme we use am4core.useTheme(theme) function.
It takes only one parameter - a reference to a theme object.
am4core.useTheme(am4themes_animated);am4core.useTheme(am4themes_animated);Now, any chart object created after useTheme() call, regardless of method of its creation, will have “Animated” theme applied to it.
Multiple themes
Section titled “Multiple themes”amCharts 4 does not limit to a single theme. You can have many useTheme() calls for different themes. This allows you to apply multiple themes to the same chart, so you can mix and match their properties.
For example I want to make my charts nicely animated, as well as use Material color palette. I can go ahead and apply two themes:
// ... other importsimport am4themes_animated from "@amcharts/amcharts4/themes/animated";import am4themes_material from "@amcharts/amcharts4/themes/material";
// Apply the themesam4core.useTheme(am4themes_animated);am4core.useTheme(am4themes_material);
// Create the charts// ...<script src="//www.amcharts.com/lib/4/themes/animated.js"></script><script src="//www.amcharts.com/lib/4/themes/material.js"></script>
<script>// Apply the themesam4core.useTheme(am4themes_animated);am4core.useTheme(am4themes_material);
// Create the charts// ...</script>Other topics
Section titled “Other topics”Different themes to different charts
Section titled “Different themes to different charts”It is possible to apply different themes to different charts on the same document.
To do so, follow this mantra:
- Call
useTheme()with themes for the first chart; - Create the first chart;
- Call
unuseTheme()for the themes you don’t want to be applied to subsequent charts; - Call
useTheme()with themes for the second chart; - Create the second chart;
- Rinse and repeat.
// Setting the theme to be applied to the first chartam4core.useTheme(am4themes_animated);
// Create the first chart// ...
// Unuse the theme from the first chartam4core.unuseTheme(am4themes_animated);
// Setting the theme to be applied to the second chartam4core.useTheme(am4themes_material);
// Create the second chart// ...// Setting the theme to be applied to the first chartam4core.useTheme(am4themes_animated);
// Create the first chart// ...
// Unuse the theme from the first chartam4core.unuseTheme(am4themes_animated);
// Setting the theme to be applied to the second chartam4core.useTheme(am4themes_material);
// Create the second chart// ...BTW You can “unset” all active themes at once, by calling am4core.unuseAllThemes().
Creating custom themes
Section titled “Creating custom themes”Special-use themes
Section titled “Special-use themes”Among other themes that are mostly color-related, amCharts 4 comes with a few special-use themes.
Patterns theme
Section titled “Patterns theme”This accessibility-oriented theme automatically fills Column, Line, or Pie series with a distinctive patterns, easily visible by people with reduced vision and color blindness.
Microchart theme
Section titled “Microchart theme”Microcharts or sparklines are super-small charts that can be used as inline text elements, or parts as extremely condensed dashboards where screen estate is extremely precious.
“microchart” theme bundled with amCharts 4 automatically disables a bunch of elements such as axis labels, grid, axis tooltips, and similar, making the charts instantaneously usable in small containers.