On this page
- Drupal version compatibility
- Introduction
- Supported charting libraries
- Installation
- Option 1: Using composer (Recommended)
- Option 2: Using the composer merge plugin
- Option 3: Manual installation
- Creating charts in the user interface
- Creating charts with Views
- Creating combo charts
- Creating charts with a chart field
- Creating charts with chart blocks
[5.x] Getting Started
Drupal version compatibility
- Drupal 10.3 || 11 || 12
Introduction
The Charts module helps site builders create data visualizations without writing any code. It also provides a framework for developers to build custom solutions. The system is made of a "core" module that handles the logic and several "submodules" that connect to specific charting tools.
More up-to-date documentation is available here: https://drupalcharts.info.
Supported charting libraries
The core module does not create visuals on its own. You must install at least one submodule for a specific library to render your data. Charts supports:
Each submodule acts as a translator, taking the data from Drupal and turning it into a format the specific JavaScript library understands.
Note: If you want a visual color picker for your chart settings, install the Color Field module.
Installation
By default, the module loads the necessary files from a Content Delivery Network (CDN), which is a collection of servers that deliver web content. If you prefer to host these files on your own server for privacy or performance reasons, you can place them in your /libraries folder using one of the methods below.
Option 1: Using composer (Recommended)
Composer is a tool used to manage all the different parts and "packages" that make up your Drupal site. This method treats the JavaScript library as a project package.
- Ensure the
composer/installerspackage is installed in your project. - Check your
composer.jsonfile forinstaller-paths. This tells Drupal exactly where to put different types of files. You should have a path set for thedrupal-librarytype. - Add the library's information to the
repositoriessection of yourcomposer.json. Each submodule usually has aREADME.mdfile with the exact text you need to copy. For Google Charts, you would add:
{ "type": "package", "package": { "name": "google/charts", "version": "45", "type": "drupal-library", "extra": { "installer-name": "google_charts" }, "dist": { "url": "https://www.gstatic.com/charts/loader.js", "type": "file" }, "require": { "composer/installers": "~1.0" } } } - Run the download command in your terminal:
composer require --prefer-dist google/charts:45
Option 2: Using the composer merge plugin
This is a more automated way to let submodules tell your main project the libraries they need.
- Install the wikimedia/composer-merge-plugin and oomphinc/composer-installers-extender packages.
- In your main
composer.jsonfile, find theextrasection and addbower-assetandnpm-assetto theinstaller-typeslist.
"installer-types": [ "bower-asset", "npm-asset" ] - Update your
installer-pathsto include these new types so they land in your/librariesfolder:
"web/libraries/{$name}": [ "type:drupal-library", "type:bower-asset", "type:npm-asset" ] - Add the submodule's configuration file to the
merge-pluginsection under theextrasection of your project'scomposer.json, so it can be read automatically:
"merge-plugin": { "include": [ "web/modules/contrib/charts/modules/charts_highcharts/composer.json" ] } - Run the
composer requirecommand mentioned in that specific submodule's instructions.
Option 3: Manual installation
You can download the JavaScript files yourself and put them in the /libraries folder. The module will recognize them as long as they are placed in the correct directory.
Creating charts in the user interface
You can manage your global settings, like default colors, at /admin/config/content/charts. Once you pick a default library, more specific options for that library appear.
There are three options for creating a chart within the UI:
Creating charts with Views
Views is a powerful Drupal tool used to fetch and display lists of content.
- Create a new view:
- Go to
admin/structure/views/add. - Pick Chart as the display format, and ensure the Show setting is set to Fields.
- Go to
- Add a label field: Under the Fields section, add the data you want to use for labels (like "Event Title").
These will be the names on your chart axes or pie slices. - Add data fields: Add the numeric fields for your data.
The names of these fields will appear in the legend. Pie charts usually only work with a single data field. - Handle non-numeric data (Aggregation): If your content doesn't have a number field, use Aggregation.
This feature groups data together. By turning on aggregation and using the count function, you can count how many times an item appears and turn that into a chartable number. - Configure the display:
- Click Settings next to the Chart format.
- Choose your library, the chart type, and which fields represent the labels and data.
- Save your view: Save the view to finish your chart.
Tip: It is often easier to start with a Table display to make sure your numbers are correct. Once the data looks right, switch the format to Chart.
Creating combo charts
A combo chart is a single visualization that uses two different types of charts at once, like a bar chart with a trend line over it.
- Add a Chart attachment display to your existing view.
- Use the settings in the middle column of the view to "attach" this to your main chart.
- Choose if this extra data should use the main Y-axis (the vertical line on the left) or a secondary Y-axis on the right.
Note: You will need to configure the Settings in the Format section.
Creating charts with a chart field
Use this method for "static" data—information that you type in manually for a specific piece of content (such as a single article or "node") rather than data pulled from across the site.
- Add a Chart field to your content type through the Manage Fields tab.
- When you create a new page, you can choose the library and chart type directly on the edit screen.
- Enter your data into the table or upload a CSV.
Creating charts with chart blocks
This is the best option for using Layout Builder, which is Drupal's visual page editor, or for placing the same chart in different sidebars across your site.
- Add a Chart Block through the block layout or layout builder interface.
- Configure your library and chart type.
- Provide your data using the manual table or by uploading a CSV.
Help improve this page
You can:
- Log in, click Edit, and edit this page
- Log in, click Discuss, update the Page status value, and suggest an improvement
- Log in and create a Documentation issue with your suggestion