• Molecule
  • CORE COMPONENT
  • Taxonomic name: M-DOUGHNUT-CHART
  • Extension: CHARTS
  • Added on: v3.0.0 (15/09/17)
  • Updated on: v5.6.0 (20/04/21)

Doughnut charts

Use doughnut charts to visually display an animated percentage amount.


Design and usage

Use doughnut charts to visually display:

  • A single animated segment - showing an animated numeric figure, like a percentage amount;
  • 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

All three doughnut 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 doughnut circle.

Accessibility and screen readers

  • To ensure the component meets accessibility standards, the component must have a 3px divider between each of the doughnut 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 doughnut graphic.

Placement

  • The doughnut 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 doughnut.
  • Two doughnut charts with keys can sit side by side on the full 12 column grid.
  • Doughnut charts should only be used on white backgrounds.
  • Do not use a multi-segment doughnut (with a legend (key) to the right or beneath) in the same section as a single segment doughnut.

Examples

Single animated segment doughnuts

Structure

  • Chart value can only be placed inside the chart circle.
  • The numerical or percentage value is h1 semi-bold using #5c596d (heading grey).
  • The body copy underneath the numerical or percentage value is 16px using the #444 (body copy grey).
  • The colour of the segment can be any accent colour; the default is accent light blue (#1a61bd).
  • Do not attempt to change the colour of the blank segment; this should always be #ccc.

Placement

  • Do not use doughnuts with a key to the right or beneath in the same section as doughnuts with numerical / percentage values inside the doughnut.

Use case and exception scenarios

  • Used to represent a single percentage or numerical value.

Interactive example

Code example

<div class="m-doughnut-chart" data-module="m-doughnut-chart" data-amount="..." data-color="...">
	<div class="m-doughnut-chart__inner">
		<div class="m-doughnut-chart__background">
			<img src="..." decoding="async" width="285" height="285" alt="" />
		</div>
		<p class="m-doughnut-chart-summary">
			<span class="m-doughnut-chart-summary__number">...</span>
			<span class="m-doughnut-chart-summary__title">...</span>
		</p>
	</div>
</div>

Multi-segment doughnuts

Structure

  • All multi-segment doughnuts must be accompanied by a legend (key); this contains the labels and values for the segments of the doughnut chart.
  • The chart legend (key) can be placed to the right or beneath the chart.
  • The chart can show from 1 to 5 segments.
  • Each of the five potential segments will have a specific colour which must always be placed in the same order:

    • Blank segment (for a single segment doughnut): #ccc (defining grey)
    • 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 doughnut.
  • The colours in the legend (key) label must match the appropriate segments in the doughnut.

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 doughnuts 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 1-5 segments of data.

Interactive example

Code example

With fallback image
<div class="o-chart [ Modifiers ]">
	<div class="m-doughnut-chart 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><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><span class="m-chart-summary__number">...</span><span class="m-chart-summary__title">...</span></li>
		</ul>
	</div>
</div>

Doughnuts 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.

Interactive example

Code example

<div class="m-card m-card--image-left m-card--50 [ Modifiers ]">
	<div class="m-card-image m-card-image--doughnut">
		<div class="m-doughnut-chart" data-module="m-doughnut-chart" data-amount="..." data-color="...">
			<div class="m-doughnut-chart-inner">
				<div class="m-doughnut-chart__background">
					<img src="./v.2023.01/shared/assets/themes-icons/[ icon library version ]/[ organisation ]/[ theme name ]/placeholder/doughnut-static.svg" decoding="async" width="285" height="285" alt="" />
				</div>
				<p class="m-doughnut-chart-summary">
					<span class="m-doughnut-chart-summary__number">...</span>
					<span class="m-doughnut-chart-summary__title">...</span>
				</p>
			</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 single segment chart, a percentage amount is required and should be specified in the data-amount attribute; this only needs to be the numeric value (the % symbol is not required). The same figure should also be entered as plain text in the m-doughnut-chart-summary__number element, this time with the % symbol included.

<div class="m-doughnut-chart" data-module="m-doughnut-chart" data-amount="67" data-color="accent-dark-5">

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--multisegment" data-module="m-doughnut-chart" data-amount="67,153,32,396,256" >

Setting the colour of the chart segments

For the single segment charts, the default colour for the segment is #1a61bd (accent light blue). The segment colour can be changed to any colour in the Framework accent colour palette described on the style guide colour page by adding the data-color attribute with the appropriate colour name (using a dash instead of a space), for example data-color="accent-dark-5". For Abeille Assurances themes only, Abeille Assurances Yellow ('accent-light-5') and Abeille Assurances Blue ('aviva-blue') are available to use as segment colours.

In addition, a m-chart-summary__bullet--[ Modifier ] class should be used on the list item for the bullet point in the chart summary so that the bullet colour matches the segment colour, for example, m-chart-summary__bullet--accent-dark-5 if the data-color attribute is set to 'accent-dark-5'.

For the multi-segment chart, the colours used for the segments are preset for accessibility reasons and can not be overridden.

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 doughnut 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.

To use legacy theme colours, call the setSettings function from the m-doughnut-chart element with a JavaScript object containing the following:

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

For the single segment chart a fallback image of the chart should be made available is possible. If this is not possible to generate basic fallback image is located at /assets/themes-icons/[ icon library version ]/[ organisation ]/[ theme name ]/placeholder/doughnut-static.svg.

For the multi-segment chart, 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.

  • Doughnut 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" />

Notes for testers

  • For single segment chart ensure that a fallback image is specified and that, if it is not the default, it matches the colour and percentage as on the JavaScript-enabled version.

Classes overview

The following table gives you a quick overview of the CSS classes that can be applied.

Class Outcome Required Applied to Comments
.m-card-image--doughnut Modifier to add to the parent m-card-image div to ensure the doughnut chart displays correctly within a card   .m-card-image  
.m-doughnut-chart Base style for the doughnut chart container Yes    
.m-doughnut-chart-inner Style for the internal wrapper (removed by JS but required for non-JS version) Yes .m-doughnut-chart > div Required for single segment doughnuts, and multi-segment doughnuts with custom fallback images
.m-doughnut-chart__background Style for the non-JS fallback image container Yes .m-doughnut-chart-inner > div Required for doughnuts with custom fallback images
.m-doughnut-chart-summary Style for the text content of the chart Yes .m-doughnut-chart-inner > p Additional CSS class used to create a single segment chart only
.m-doughnut-chart-summary__number Style for the percentage element of the text content Yes .m-doughnut-chart-inner > p Additional CSS class used to create a single segment chart only
.m-doughnut-chart-summary__title Style for the title element of the text content Yes .m-doughnut-chart-inner > div Additional CSS class used to create a single segment chart only
.o-chart Base style for multi-segment doughnut chart and summary data chart Yes   Additional CSS class used to create a multi-segment chart only
.o-chart--summary-below Modifier for positioning the chart data below the doughnut chart   .o-chart Additional CSS class used to create a multi-segment chart only
.m-doughnut-chart--multisegment Base selector style for adding additional multi-segment doughnut chart styling Yes .m-doughnut-chart Additional CSS class used to create a multi-segment chart only
.m-chart-container Container for text content and the summary chart Yes .o-chart > div Additional CSS class used to create a multi-segment chart only
.m-chart-summary Style for the text content of the chart Yes .m-chart-container > ul Additional CSS class used to create a multi-segment chart only
.m-chart-summary--reversed Modifier style for when reversing the number and title order of the chart data   .m-chart-summary Additional CSS class used to create a multi-segment chart only
.m-chart-summary--right Modifier style to right align titles in the chart data   .m-chart-summary Additional CSS class used to create a multi-segment chart only
.m-chart-summary--3-character Modifier style to allow left aligned titles following a 3 character value   .m-chart-summary Additional CSS class used to create a multi-segment chart only
.m-chart-summary--5-character Modifier style to allow left aligned titles following a 5 character value   .m-chart-summary Additional CSS class used to create a multi-segment chart only
.m-chart-summary--7-character Modifier style to allow left aligned titles following a 7 character value   .m-chart-summary Additional CSS class used to create a multi-segment chart only
.m-chart-summary--10-character Modifier style to allow left aligned titles following a 10 character value   .m-chart-summary Additional CSS class used to create a multi-segment chart only
.m-chart-summary--13-character Modifier style to allow left aligned titles following a 13 character value   .m-chart-summary Additional CSS class used to create a multi-segment chart only
.m-chart-summary__number Style for the value element of the text content Yes .m-chart-summary > li span Additional CSS class used to create a multi-segment chart only
.m-chart-summary__title Style for the title element of the text content Yes .m-chart-summary > li span Additional CSS class used to create a multi-segment chart only
.m-chart-summary__segment1 Style for the list element in the chart summary if the first segment of the chart is highlighted Yes .m-chart-summary > li span Additional CSS class used to create a highlight segment chart only
.m-chart-summary__segment2 Style for the list element in the chart summary if the second segment of the chart is highlighted Yes .m-chart-summary > li span Additional CSS class used to create a highlight segment chart only
.m-chart-summary__segment3 Style for the list element in the chart summary if the third segment of the chart is highlighted Yes .m-chart-summary > li span Additional CSS class used to create a highlight segment chart only
.m-chart-summary__segment4 Style for the list element in the chart summary if the fourth segment of the chart is highlighted Yes .m-chart-summary > li span Additional CSS class used to create a highlight segment chart only
.m-chart-summary__segment5 Style for the list element in the chart summary if the fifth segment of the chart is highlighted Yes .m-chart-summary > li span Additional CSS class used to create a highlight segment chart only

Component releases

  • Added on: v3.0.0 (15/09/17)
  • 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.

Full version history

A full history of changes and enhancements detailing all minor and major updates to the component.

View full version history

Want something new in Framework, or to chat about an issue you're having with it?

Contact the team