The Ignite UI for Web Components Donut Chart is similar to the Pie Chart, proportionally illustrating the occurrences of a variable. The donut chart can display multiple variables in concentric rings, and provides built-in support for visualizing hierarchical data. The rings are capable of being bound to a different data item, or they can share a common data source.
Web Components Donut Chart Example
You can create Donut Chart using the IgcDoughnutChartComponent control by binding your data as shown in the example below.
EXAMPLE
DATA
TS
HTML
CSS
exportclassEnergyGlobalDemandItem{
publicconstructor(init: Partial<EnergyGlobalDemandItem>) {
Object.assign(this, init);
}
public value: number;
public category: string;
public summary: string;
}
exportclassEnergyGlobalDemandextendsArray<EnergyGlobalDemandItem> {
publicconstructor(items: Array<EnergyGlobalDemandItem> | number = -1) {
if (Array.isArray(items)) {
super(...items);
} else {
const newItems = [
new EnergyGlobalDemandItem(
{
value: 37,
category: `Cooling`,
summary: `Cooling 37%`
}),
new EnergyGlobalDemandItem(
{
value: 25,
category: `Residential`,
summary: `Residential 25%`
}),
new EnergyGlobalDemandItem(
{
value: 12,
category: `Heating`,
summary: `Heating 12%`
}),
new EnergyGlobalDemandItem(
{
value: 11,
category: `Lighting`,
summary: `Lighting 11%`
}),
new EnergyGlobalDemandItem(
{
value: 15,
category: `Other`,
summary: `Other 15%`
}),
];
super(...newItems.slice(0));
}
}
}
ts
<!DOCTYPE html><html><head><title>Sample | Ignite UI | Web Components | infragistics</title><metacharset="UTF-8" /><linkrel="shortcut icon"href="https://static.infragistics.com/xplatform/images/browsers/wc.png" ><linkrel="stylesheet"href="https://fonts.googleapis.com/icon?family=Material+Icons" /><linkrel="stylesheet"href="https://fonts.googleapis.com/css?family=Kanit&display=swap" /><linkrel="stylesheet"href="https://fonts.googleapis.com/css?family=Titillium Web" /><linkrel="stylesheet"href="https://static.infragistics.com/xplatform/css/samples/shared.v8.css" /><linkrel="stylesheet"href="/src/index.css"type="text/css" /></head><body><divid="root"><divclass="container sample"><divclass="legend-title">
Global Electricity Demand by Energy Use
</div><divclass="legend"><igc-item-legendname="legend"id="legend"orientation="Horizontal"></igc-item-legend></div><divclass="container fill"><igc-doughnut-chartname="chart"id="chart"allow-slice-explosion="true"><igc-ring-seriesname="series"id="series"label-member-path="summary"labels-position="OutsideEnd"label-extent="30"value-member-path="value"legend-label-member-path="category"outlines="white"radius-factor="0.6"start-angle="30"></igc-ring-series></igc-doughnut-chart></div></div></div><!-- This script is needed only for parcel and it will be excluded for webpack -->
<% if (false) { %><scriptsrc="src/index.ts"></script><% } %>
</body></html>html
/* shared styles are loaded from: *//* https://static.infragistics.com/xplatform/css/samples */css
Like this sample? Get access to our complete Ignite UI for Web Components toolkit and start building your own apps in minutes. Download it for free.
Web Components Donut Chart Recommendations
Are Web Components Donut Charts right for your project?
Donut Charts are appropriate for small data sets and are easy to read at a glance. Donut charts are just one type of part-to-whole visualization. Others include:
The Web Components Donut Chart includes interactive features that give the viewer tools to analyze data, like:
Legends
Slice Explosion
Slice Selection
Chart Animations
Best Practices for Donut Charts
Using multiple data sets to display your data in a ring display.
Placing the information such as values or labels, within the hole of the donut for quick explanation of data.
Comparing slices or segments as percentage values in proportion to a total value or whole.
Showing how a group of categories is broken into smaller segments.
Ensuring data segments add up to 100%.
Ensuring the color palette is distinguishable for segments/slices of the parts.
When not to use a Donut Chart
Comparing change over time —use a Bar, Line or Area chart.
Requiring precise data comparison —use a Bar, Line or Area chart.
You have more than 6 or 8 segments (high data volume) — consider a Bar, Line or Area chart if it works for your data story.
It would be easier for the viewer to perceive the value difference in a Bar chart.
You have negative data, as this can not be represented in a donut chart.
Web Components Donut Chart - Slice Selection
The Web Components Donut Chart has the ability to select slices on click. Optionally, you may apply a single custom visual style to the selected slices. The SliceClick event is raised when the user clicks on a slice. Enabling slice selection allows you to modify the slice's selection upon click. The following sample demonstrates how to enable slice selection and set the selected slice color to gray.
<!DOCTYPE html><html><head><title>DoughnutChartSelection</title><metacharset="UTF-8" /><linkrel="shortcut icon"href="https://static.infragistics.com/xplatform/images/browsers/wc.png" ><linkrel="stylesheet"href="https://fonts.googleapis.com/icon?family=Material+Icons" /><linkrel="stylesheet"href="https://fonts.googleapis.com/css?family=Kanit&display=swap" /><linkrel="stylesheet"href="https://fonts.googleapis.com/css?family=Titillium Web" /><linkrel="stylesheet"href="https://static.infragistics.com/xplatform/css/samples/shared.v8.css"type="text/css" /></head><body><divid="root"><divclass="container sample" ><divclass="options vertical"><spanclass="legend-title">Global Electricity Demand by Energy Use</span><divclass="legend"><igc-item-legendid="legend"orientation="Horizontal"></igc-item-legend></div></div><divclass="container relative"><divclass="container-overlay"><igc-doughnut-chartid="chart"width="100%"height="100%"allow-slice-selection="true"inner-extent="0.6"><igc-ring-seriesname="ringSeries"id="ringSeries"label-member-path="Summary"labels-position="OutsideEnd"label-extent="30"value-member-path="MarketShare"legend-label-member-path="Category"radius-factor="0.7"start-angle="30"
></igc-ring-series></igc-doughnut-chart><divclass="overlay-center"style="line-height: 1.1;"><labelid="selectedSliceLabel"class="options-label"style="font-size: 1.2rem;"></label><labelid="selectedSliceValue"class="options-label"style="font-size: 2.2rem;"></label></div></div></div></div></div><!-- This script is needed only for parcel and it will be excluded for webpack -->
<% if (false) { %><scriptsrc="src/index.ts"></script><% } %>
</body></html>html
/* shared styles are loaded from: *//* https://static.infragistics.com/xplatform/css/samples */css
Web Components Donut Chart - Multiple Rings
It is possible to have a multiple ring display in the Web Components Donut Chart, with each of the rings capable of being bound to a different data item, or they can share a common data source. This can be helpful if you need to display your data as tiers that have an underlying common category, such as the season to month data display below:
EXAMPLE
CalendarMonths.ts
CalendarSeasons.ts
TS
HTML
CSS
exportclassCalendarMonthsItem{
publicconstructor(init: Partial<CalendarMonthsItem>) {
Object.assign(this, init);
}
public value: number;
public label: string;
}
exportclassCalendarMonthsextendsArray<CalendarMonthsItem> {
publicconstructor(items: Array<CalendarMonthsItem> | number = -1) {
if (Array.isArray(items)) {
super(...items);
} else {
const newItems = [
new CalendarMonthsItem(
{
value: 1,
label: `December`
}),
new CalendarMonthsItem(
{
value: 1,
label: `January`
}),
new CalendarMonthsItem(
{
value: 1,
label: `February`
}),
new CalendarMonthsItem(
{
value: 1,
label: `March`
}),
new CalendarMonthsItem(
{
value: 1,
label: `April`
}),
new CalendarMonthsItem(
{
value: 1,
label: `May`
}),
new CalendarMonthsItem(
{
value: 1,
label: `June`
}),
new CalendarMonthsItem(
{
value: 1,
label: `July`
}),
new CalendarMonthsItem(
{
value: 1,
label: `August`
}),
new CalendarMonthsItem(
{
value: 1,
label: `September`
}),
new CalendarMonthsItem(
{
value: 1,
label: `October`
}),
new CalendarMonthsItem(
{
value: 1,
label: `November`
}),
];
super(...newItems.slice(0));
}
}
}
ts
exportclassCalendarSeasonsItem{
publicconstructor(init: Partial<CalendarSeasonsItem>) {
Object.assign(this, init);
}
public value: number;
public label: string;
}
exportclassCalendarSeasonsextendsArray<CalendarSeasonsItem> {
publicconstructor(items: Array<CalendarSeasonsItem> | number = -1) {
if (Array.isArray(items)) {
super(...items);
} else {
const newItems = [
new CalendarSeasonsItem(
{
value: 4,
label: `Winter`
}),
new CalendarSeasonsItem(
{
value: 4,
label: `Spring`
}),
new CalendarSeasonsItem(
{
value: 4,
label: `Summer`
}),
new CalendarSeasonsItem(
{
value: 4,
label: `Fall`
}),
];
super(...newItems.slice(0));
}
}
}
ts