Doughnut Chart

Overview

A doughnut (or donut) chart is a pie chart with a "hole" – a blank circular area in the center. The chart is divided into parts that show the percentage each value contributes to a total.

Like the regular pie chart, the doughnut chart is used with small sets of data to compare categories. It drives attention from the area taken by each part to emphasize the length of arcs. The blank space also allows displaying some additional information in the center: for example, labels, the name of a selected category, or the chart title.

The Doughnut chart is a modification of the Pie chart and shares almost all the setting with it, so this article explains just how to create a basic Doughnut chart and configure its labels. To learn about other settings, read the Pie Chart article. See also Chartopedia: Doughnut Chart.

Quick Start

To create a Doughnut chart, use the anychart.pie() chart constructor and the innerRadius() method to set the inner radius. The radius is 0 by default and can be set either as a value or a percentage of the chart's bounds.

The following sample shows how to create a basic Doughnut chart:

// create data
var data = [
  {x: "A", value: 637166},
  {x: "B", value: 721630},
  {x: "C", value: 148662},
  {x: "D", value: 78662},
  {x: "E", value: 90000}
];

// create a pie chart and set the data
chart = anychart.pie(data);

/* set the inner radius
(to turn the pie chart into a doughnut chart)*/
chart.innerRadius("30%");

// set the container id
chart.container("container");

// initiate drawing the chart
chart.draw();

Playground

Settings

The Doughnut chart is a modification of the Pie chart, so these two types share almost all the settings. You can find more settings in this article: Pie Chart.

Also, in AnyChart there are many settings that are configured in the same way for all chart types, including the Doughnut chart (for example, legend and interactivity settings): General Settings.

In addition, see the full list of methods available for the Pie chart: anychart.charts.Pie

Special Settings

Labels

Outer Labels

By default, labels are placed on the Doughnut chart. However, you can place them outside of the chart by using the position() method with the "outside" parameter:

// set the position of labels
chart.labels().position("outside");

To configure connectors (the lines connecting labels with slices), call the connectorStroke() method:

// configure connectors
chart.connectorStroke({color: "#595959", thickness: 2, dash:"2 2"});

Another setting available for outer labels is outsideLabelsCriticalAngle().

In this sample, there are outside labels with customized connectors:

Playground

Inner Labels

To place labels into the blank area in the center of a Doughnut chart, call the position() method with the "inside" parameter. You can also configure the offset of the inner labels by using the isideLabelsOffset() method.

The sample below shows a Doughnut chart with inner labels, the offset is -75%:

// set the position of labels
chart.labels().position("inside");

// set the offset for the labels
chart.insideLabelsOffset("-75%");

Playground

Center Content

The center() method that provides the access to anychart.core.pie.Center object provide a very flexible way to place almost anything into the center of the Donut chart.

In this section we will provide several typical use cases along with the samples and all code you will need to create charts like in your application.

Center Label

To put some text in the center of a donut create a label and assign it to the center.

// create and configure a label
var label = anychart.standalones.label();
label.text("Activities");
label.width("100%");
label.height("100%");
label.fontSize(30);
label.fontColor("#60727b");
label.hAlign("center");
label.vAlign("middle");

// Set center content.
chart.center().content(label);

Playground

Chart

To put another chart in the center of the donut chart create a chart and specify it as the center content:

// create and configure a pie chart
var chart1 = anychart.pie(data);
chart1.innerRadius("75%");

// create a bar chart
var chart2 = anychart.bar(data);

// set bar chart as the center content of a pie chart
chart1.center().content(chart2);

Playground

Map

To put a map in the center of the donut create a map and specify it as the center content

// create pie chart and configure it
var pie = anychart.pie(data);
pie.innerRadius('85%');;

// create a map and configure it
var map = anychart.map();
map.geoData('anychart.maps.united_states_of_america');

// set map as the center of the chart 
pie.center().content(map);

Playground

Custom Drawing

You can put any kind of custom drawing created with the Graphics engine. Here a basic sample with several simple shapes:

// create pie chart and configure it
var pie = anychart.pie(data);
// create a layer and put some shapes in it
var layer = anychart.graphics.layer();
// draw the square
layer.rect(25, 50, 350, 300);
// set layer as the center of the chart 
pie.center().content(layer);

Playground