Drupal is a registered trademark of Dries Buytaert
drupal 11.3.7 Update released for Drupal core (11.3.7)! drupal 11.2.11 Update released for Drupal core (11.2.11)! drupal 10.6.7 Update released for Drupal core (10.6.7)! drupal 10.5.9 Update released for Drupal core (10.5.9)! cms 2.1.1 Update released for Drupal core (2.1.1)! drupal 11.3.6 Update released for Drupal core (11.3.6)! drupal 10.6.6 Update released for Drupal core (10.6.6)! cms 2.1.0 Update released for Drupal core (2.1.0)! bootstrap 8.x-3.40 Minor update available for theme bootstrap (8.x-3.40). menu_link_attributes 8.x-1.7 Minor update available for module menu_link_attributes (8.x-1.7). eca 3.1.1 Minor update available for module eca (3.1.1). layout_paragraphs 2.1.3 Minor update available for module layout_paragraphs (2.1.3). ai 1.3.3 Minor update available for module ai (1.3.3). ai 1.2.14 Minor update available for module ai (1.2.14). node_revision_delete 2.0.3 Minor update available for module node_revision_delete (2.0.3). moderated_content_bulk_publish 2.0.52 Minor update available for module moderated_content_bulk_publish (2.0.52). klaro 3.0.10 Minor update available for module klaro (3.0.10). klaro 3.0.9 Minor update available for module klaro (3.0.9). layout_paragraphs 2.1.2 Minor update available for module layout_paragraphs (2.1.2). geofield_map 11.1.8 Minor update available for module geofield_map (11.1.8).

charts_twig

128 sites Security covered
View on drupal.org

This module provides a Twig extension that enables you to generate charts in Twig using that Charts module API. Make sure you've installed the Charts module (including at least one submodule (and associated library), and set a default library at /admin/config/content/charts).

Recommended way of using chart()

We recommended you use the chart() function by passing it a single "definition" array that defines the entire chart. This approach is more flexible than the 1.0.x version used and allows for advanced features like multiple axes.

Simple Example

Here is a basic example that builds a two-series column chart.

{% set my_chart = { id: 'my_twig_chart', chart_type: 'column', title: 'The Chart Title'|t, series: [ { title: 'My first series'|t, data: [10, 20, 30], color: 'purple', }, { title: 'My second series'|t, data: [8, 14, 22], }, ], axes: { xaxis: { type: 'chart_xaxis', title: 'X-Axis Label'|t, labels: ['a', 'b', 'c'], } } } %}
{{ chart(my_chart) }}

Advanced Example: Multiple Y-Axes

This example demonstrates a mixed-type chart with two Y-axes. A line series is plotted against a right-side axis, and a column series is plotted against the left-side axis.

{% set complex_chart = { id: 'performance_chart', chart_type: 'column', title: 'Website Performance'|t, series: [ { title: 'Pageviews (Millions)'|t, data: [1.5, 1.7, 2.0], target_axis: 'yaxis_pageviews', }, { title: 'Load Time (ms)'|t, data: [450, 400, 380], target_axis: 'yaxis_loadtime', chart_type: 'line', }, ], axes: { xaxis: { type: 'chart_xaxis', title: 'Month'|t, labels: ['Jan', 'Feb', 'Mar'], }, yaxis_pageviews: { type: 'chart_yaxis', title: 'Pageviews (M)'|t, }, yaxis_loadtime: { type: 'chart_yaxis', title: 'Load Time (ms)'|t, opposite: true, }, }, raw_options: { subtitle: { text: 'A subtitle from raw options'|t } } } %}
{{ chart(complex_chart) }}

Legacy way of using chart()

For backwards compatibility, the chart() function still accepts a long list of arguments.

{% set title = 'The Chart Title' %} {% set data = [10, 20, 30] %} {% set data2 = [8, 14, 22] %} {% set series = { 'my_first_series' : { 'title' : 'My first series', 'data' : data, 'color': 'purple' }, 'my_second_series' : { 'title' : 'My second series', 'data' : data2 } } %} {% set xaxis = { 'title' : 'X-Axis Label', 'labels' : ['a', 'b', 'c'] } %}
{{ chart('my_twig_chart', 'column', title, series, xaxis, [], []) }}

Translation

If you plan to use translation on your site, you should use the |t filter
for any user-facing strings, as shown in the examples above.
See:https://www.drupal.org/docs/8/api/translation-api/overview

Support

Support Charts and Similar Modules

The Charts module is part of an ecosystem dedicated to empowering users to store, visualize, and analyze their data. Please consider helping to financially support the Charts ecosystem by becoming a backer or by making a one-time contribution to say thanks by joining the Charts module's Open Collective.

Become a Backer Say Thanks

There are plenty of other ways to help maintain, further enhance, and support the Charts module, as detailed in how to contribute.

Activity

Total releases
3
First release
Jan 2025
Latest release
4 months ago
Release cadence
155 days
Stability
67% stable

Release Timeline

Releases

Version Type Release date
2.0.0 Stable Nov 24, 2025
2.0.x-dev Dev Nov 24, 2025
1.0.6 Stable Jan 19, 2025