- Taxonomic name: M-DOUGHNUT-CHART
- Extension: CHARTS
- Added on: v4.7.0 (01/03/19)
- Updated on: v5.6.0 (20/04/21)
Pie charts
Use pie charts to visually display an animated percentage amount
Design and usage
Use pie charts to visually display:
- Multiple segments - to present up to 5 segments of numerical information;
- Highlighted segments - to show 100% of a pot and further information about each segment.
Shared rules
The pie variations carry these rules:
Structure
- When a chart is revealed for the first time within the viewport it will animate clockwise its data set completing the pie circle.
Accessibility and screen readers
- To ensure the component meets accessibility standards, the component must have a 3px divider between each of the pie segments.
Non-JS requirements and considerations
- When JavaScript is not available, if no static fall back image is supplied, then the key will appear without the pie graphic.
Placement
- The pie chart and key must sit within the grid, with the block consuming six columns of the grid if the key is placed to the right of the pie chart.
- Two pie charts with keys can sit side by side on the full 12 column grid.
- Pie charts should only be used on white backgrounds.
Multi-segment pie chart
Structure
- All multi-segment pie charts must be accompanied by a legend (key); this contains the labels and values for the segments of the pie chart.
- The chart legend (key) can be placed to the right or beneath the chart.
- The chart can show a minimum of 2 and a maximum of 5 segments.
-
Each of the five potential segments will have a specific colour which must always be placed in the same order:
- Segment 1: #1a61bd
- Segment 2: #a9b2c6
- Segment 3: #5a8ccc
- Segment 4: #c2c8d5
- Segment 5: #7988a9
-
Other atoms can be placed within the key lock-up, including:
- A title
- A total (if numerical values)
- A primary or secondary call to action or a text-link
- A block of copy
Labels
- The legend (key) will contain the labels for each of the segments in the pie chart.
- The colours in the legend (key) label must match the appropriate segments in the pie chart.
Accessibility and screen readers
- To ensure the component meets accessibility standards, the component must have a legend (key) with labels.
Placement
- If needed, up to three pie charts can be placed side by side; in this instance the keys will be placed below the charts.
Use case and exception scenarios
- To display percentage or numerical data to customers, such as pension values or investments with 2-5 segments of data.
- For charts with only 1 segment and/or to use alternative accent colours; see doughnut charts.
Pie charts with highlighted segments
Structure
-
Follows the same rules as a multi-segment chart except:
- The first chart shown is the full data set you wish to use.
- Each following chart refers to a single highlighted section of the first chart.
Labels
- The full multi-segment chart shows a legend (key) for all segments of the data set.
- Highlighted charts only show a legend (key) for that single highlighted section.
Use case and exception scenarios
- Use two or more multi-segmented charts with highlights to explain individual sections from one multi-segment card carrying the complete data set.
Examples
Interactive example
Code example
With fallback image
<div class="o-chart [ Modifiers ]">
<div class="m-doughnut-chart m-doughnut-chart--pie m-doughnut-chart--multisegment" data-module="m-doughnut-chart" data-amount="...">
<div class="m-doughnut-chart__inner">
<div class="m-doughnut-chart__background">
<img src="..." decoding="async" width="285" height="285" alt="..." />
</div>
</div>
</div>
<div class="m-chart-container">
<ul class="m-chart-summary [ Modifiers ]">
<li class="[ Modifier ]">
<span class="m-chart-summary__number">
...
</span>
<span class="m-chart-summary__title">
...
</span>
</li>
...
</ul>
</div>
</div>
Without fallback image
<div class="o-chart [ Modifiers ]">
<div class="m-doughnut-chart m-doughnut-chart--multisegment" data-module="m-doughnut-chart" data-amount="..."></div>
<div class="m-chart-container">
<ul class="m-chart-summary [ Modifiers ]">
<li class="[ Modifier ]">
<span class="m-chart-summary__number">
...
</span>
<span class="m-chart-summary__title">
...
</span>
</li> </ul>
</div>
</div>
Pie chart in a 50:50 card
<div class="m-card m-card--image-left m-card--50 [ Modifiers ]">
<div class="m-card-image m-card-image--doughnut">
<div class="o-chart [ Modifiers ]">
<div class="m-doughnut-chart m-doughnut-chart--pie m-doughnut-chart--multisegment" data-module="m-doughnut-chart" data-amount="...">
<div class="m-doughnut-chart-inner">
<div class="m-doughnut-chart__background">
<img src="..." decoding="async" width="285" height="285" alt="" />
</div>
</div>
</div>
<div class="m-chart-container">
<ul class="m-chart-summary">
<li class="[ Modifiers ]">
<span class="m-chart-summary__number">
...
</span>
<span class="m-chart-summary__title">
...
</span>
</li>
</ul>
</div>
</div>
</div>
<div class="m-card-content">
<div class="m-card-content__inner">
<h2 class="a-heading a-heading--2 a-heading--semibold">...</h2>
<p>...</p>
</div>
</div>
</div>
Development and test
Notes for developers
Setting values for the chart
For the multi-segment chart, a list of comma separated numbers must be specified in the data-amount
attribute. The values do not need to be percentages.
<div class="m-doughnut-chart m-doughnut-chart--pie m-doughnut-chart--multisegment" data-module="m-doughnut-chart" data-amount="67,153,32,396,256" >
Multi-segment charts with highlight segments
To use highlight segments, set up a standard multi-segment chart, with the addition of a data-color
attribute. Within this, list out each segment as either 'on' (coloured) or 'off' (background colour); for example, to highlight the second segment in a three-segment chart, the attribute would read: data-color="off,on,off"
; to highlight the third and fourth segments of a five segment chart, the attribute would read: data-color="off,off,on,on,off"
. In addition, a m-chart-summary__bullet--segment[ Modifier ]
class should be used on the list item for the bullet point in the chart summary so that the bullet colour matches the highlighted segment colour, for example, m-chart-summary__bullet--segment2
if highlighting the second segment.
Extending the config
The default settings for the pie chart can be extended to change the colours available to themes. Note that the colours selected must meet accessibility standards.
For more information on this, see how to extend component configurations within JavaScript and what options are available for change.
document.addEventListener( 'frameworkready', function () {
FRAMEWORK.require([ 'blocks/m-doughnut-chart' ], function ( mDoughnutChartModule ) {
var mDoughnutChartEl = document.querySelector( '#chart' ),
mDoughnutChartInstance = mDoughnutChartModule.initInstance( mDoughnutChartEl ); mDoughnutChartInstance.setSettings({
accentSegmentColors : {
'accent-dark-1' : '#1a61bd', // Light blue
'accent-dark-2' : '#001647', // Dark blue
'accent-dark-3' : '#0e573f', // Dark green
'accent-dark-4' : '#87378e', // Light purple
'accent-dark-5' : '#421b67', // Dark purple
'accent-dark-6' : '#c01b83', // Pink
'accent-dark-7' : '#00788a', // Teal
'accent-dark-8' : '#413e45', // Dark grey
}
});
});
});
Updating chart values after load
It is possible to update the values displayed by a particular chart after initial load. To do this, the function setSettings
should be called from the m-doughnut-chart
element with a JavaScript object containing settings in the same format as below being passed into the function:
For example:
document.addEventListener( 'frameworkready', function () {
FRAMEWORK.require([ 'blocks/m-doughnut-chart' ], function ( mDoughnutChartModule ) {
var mDoughnutChartEl = document.querySelector( '#chart' ),
mDoughnutChartInstance = mDoughnutChartModule.initInstance( mDoughnutChartEl ); mDoughnutChartInstance.setSettings({
'amount' : '10,15,20,25,30',
});
});
});
Note: The key associated with the chart will not be updated, this function only redraws the chart itself.
Non-JavaScript fallback
If no image fallback is available, only the key should be shown; in this instance, add the .o-chart--no-image
to the main .o-chart
div to ensure font sizes are scaled up accordingly to meet design requirements. If no fallback image is supplied ensure no whitespace,comments etc are included within the m-doughnut-chart
element to maintain correct styling.
- Pie charts must not be used on dark accent colours.
Extension component
This component forms part of the 'charts' extension and so requires an additional stylesheet to be loaded in order to be used; include the following code in the header of your page to attach the relevant additional stylesheet:
<link media="all" href="./assets/[ theme type ]/[ release version ]/[ organisation ]/[ theme name ]/css/charts.css" rel="stylesheet" />
Classes overview
The following table gives you a quick overview of the CSS classes that can be applied.
Class | Outcome | Required | Applied to | Comments |
---|---|---|---|---|
.o-chart |
Base style for pie charts to wrap the chart and the key | Yes | |
Additional CSS class used to create a multi-segment chart only |
.m-doughnut-chart |
Base style for the pie chart container | Yes | .o-chart > div |
|
.m-doughnut-chart--pie |
Pie chart variant for doughnut charts | Yes | .m-doughnut-chart |
|
.m-doughnut-chart--multisegment |
Base selector style for adding additional multi-segment pie chart styling | Yes | .m-doughnut-chart |
Additional CSS class used to create a multi-segment chart only |
.m-card-image--doughnut |
Modifier to add to the parent m-card-image div to ensure the pie chart displays correctly within a card | .m-card-image |
||
.m-doughnut-chart-inner |
Style for the internal wrapper (removed by JS but required for non-JS version) | .m-doughnut-chart > div |
||
.m-doughnut-chart__background |
Style for the non-JS fallback image container | .m-doughnut-chart-inner > div |
||
.o-chart--summary-below |
Modifier for positioning the chart data below the pie chart | .o-chart |
||
.m-chart-container |
Container for text content and the summary chart | .o-chart > div |
Additional CSS class used to create the pie chart key | |
.m-chart-summary |
Style for the text content of the chart | .m-chart-container > ul |
||
.m-chart-summary--reversed |
Modifier style for when reversing the number and title order of the chart data | .m-chart-summary |
||
.m-chart-summary--right |
Modifier style to right align titles in the chart data | .m-chart-summary |
||
.m-chart-summary--3-character |
Modifier style to allow left aligned titles following a 3 character value | .m-chart-summary |
||
.m-chart-summary--5-character |
Modifier style to allow left aligned titles following a 5 character value | .m-chart-summary |
||
.m-chart-summary--7-character |
Modifier style to allow left aligned titles following a 7 character value | .m-chart-summary |
||
.m-chart-summary--10-character |
Modifier style to allow left aligned titles following a 10 character value | .m-chart-summary |
||
.m-chart-summary--13-character |
Modifier style to allow left aligned titles following a 13 character value | .m-chart-summary |
||
.m-chart-summary__number |
Style for the value element of the text content | .m-chart-summary > li span |
||
.m-chart-summary__title |
Style for the title element of the text content | .m-chart-summary > li span |
||
.m-chart-summary__segment1 |
Style for the list element in the chart summary if the first segment of the chart is highlighted | .m-chart-summary > li span |
||
.m-chart-summary__segment2 |
Style for the list element in the chart summary if the second segment of the chart is highlighted | .m-chart-summary > li span |
||
.m-chart-summary__segment3 |
Style for the list element in the chart summary if the third segment of the chart is highlighted | .m-chart-summary > li span |
||
.m-chart-summary__segment4 |
Style for the list element in the chart summary if the fourth segment of the chart is highlighted | .m-chart-summary > li span |
||
.m-chart-summary__segment5 |
Style for the list element in the chart summary if the fifth segment of the chart is highlighted | .m-chart-summary > li span |
Component releases
- Added on: v4.7.0 (01/03/19)
- Updated on: v5.6.0 (20/04/21)
Latest update:
- updated: To improve page load and layout times the additional attributes decoding="async", width and height must be set on all inline images.