|
| 1 | +--- |
| 2 | +title: Donut Charts |
| 3 | +page_title: Donut Charts |
| 4 | +description: "Learn how to create a Telerik UI Donut Chart for {{ site.framework }}." |
| 5 | +slug: donutcharts_aspnetcore_htmlhelper |
| 6 | +--- |
| 7 | + |
| 8 | +# Donut Charts |
| 9 | + |
| 10 | +{% if site.core %} |
| 11 | +The Telerik UI Donut Chart TagHelper and HtmlHelper for {{ site.framework }} are server-side wrappers for the Kendo UI Donut Chart widget. |
| 12 | +{% else %} |
| 13 | +The Telerik UI Donut Chart HtmlHelper for {{ site.framework }} is a server-side wrapper for the Kendo UI Donut Chart widget. |
| 14 | +{% endif %} |
| 15 | + |
| 16 | +The Donut Charts are a Pie chart variation with the ability to display data as single-series sectors from a two-dimensional circle. |
| 17 | + |
| 18 | +* [Demo page for the Donut Chart HtmlHelper](https://demos.telerik.com/{{ site.platform }}/donut-charts/index) |
| 19 | +{% if site.core %} |
| 20 | +* [Demo page for the Donut Chart TagHelper](https://demos.telerik.com/aspnet-core/donut-charts/tag-helper) |
| 21 | +{% endif %} |
| 22 | + |
| 23 | +## Getting Started |
| 24 | + |
| 25 | +Donut Charts are suitable for showing the proportions of categorical data, with the size of each piece representing the proportion of each category. In comparison to its [Pie Chart]({% slug piecharts_aspnetcore_htmlhelper %}) predecessor, it helps avoid confusion around the area parameter that often trips people up in a Pie Chart. |
| 26 | + |
| 27 | +To create Donut series in the Chart component, use the `Donut` configuration method within the `Series` configuration. |
| 28 | + |
| 29 | +* [Creating the Donut Chart](#creating-the-donut-chart) |
| 30 | +* [Configuring the labels visibility](#configuring-the-labels-visibility) |
| 31 | +* [Configuring the labels alignment](#configuring-the-labels-alignment) |
| 32 | +* [Configuring the effects overlay](#configuring-the-effects-overlay) |
| 33 | + |
| 34 | +Also, you can configure the Donut Chart for `Inline`, `Local`, and `Remote` data binding. |
| 35 | + |
| 36 | +* [Charts Data Binding](https://docs.telerik.com/{{ site.platform }}/html-helpers/charts/data-binding) |
| 37 | + |
| 38 | +## Creating the Donut Chart |
| 39 | + |
| 40 | +The following example demonstrates how to define a Donut Chart with a single series. |
| 41 | + |
| 42 | +```HtmlHelper |
| 43 | + @(Html.Kendo().Chart() |
| 44 | + .Name("chart") |
| 45 | + .Title("What is you favourite sport?") |
| 46 | + .Legend(legend => legend |
| 47 | + .Position(ChartLegendPosition.Top) |
| 48 | + ) |
| 49 | + .Series(series => { |
| 50 | + series.Donut(new dynamic[] { |
| 51 | + new {category = "Football",value = 35}, |
| 52 | + new {category = "Basketball",value = 25}, |
| 53 | + new {category = "Volleyball",value = 20}, |
| 54 | + new {category = "Rugby",value = 10}, |
| 55 | + new {category = "Tennis",value = 10} |
| 56 | + }) |
| 57 | + .Labels(labels => labels |
| 58 | + .Visible(true) |
| 59 | + .Position(ChartPieLabelsPosition.OutsideEnd) |
| 60 | + .Template("#= category # - #= kendo.format('{0:P}', percentage)#") |
| 61 | + .Background("transparent") |
| 62 | + ); |
| 63 | + }) |
| 64 | + .Tooltip(tooltip => tooltip |
| 65 | + .Visible(true) |
| 66 | + .Template("#= category # - #= kendo.format('{0:P}', percentage) #") |
| 67 | + ) |
| 68 | + ) |
| 69 | +``` |
| 70 | +{% if site.core %} |
| 71 | +```TagHelper |
| 72 | + <kendo-chart name="chart"> |
| 73 | + <chart-title text="What is you favourite sport?"></chart-title> |
| 74 | + <chart-legend position="ChartLegendPosition.Top"></chart-legend> |
| 75 | + <series-defaults type="ChartSeriesType.Donut"></series-defaults> |
| 76 | + <series> |
| 77 | + <series-item start-angle="150" name="2011" data='new dynamic[] { |
| 78 | + new {category = "Football",value = 35}, |
| 79 | + new {category = "Basketball",value = 25}, |
| 80 | + new {category = "Volleyball",value = 20}, |
| 81 | + new {category = "Rugby",value = 10}, |
| 82 | + new {category = "Tennis",value = 10} |
| 83 | + }'> |
| 84 | + <labels visible="true" |
| 85 | + position="ChartSeriesLabelsPosition.OutsideEnd" |
| 86 | + template="#= category # - #= kendo.format('{0:P}', percentage)#" |
| 87 | + background="transparent"> |
| 88 | + </labels> |
| 89 | + </series-item> |
| 90 | + </series> |
| 91 | + <tooltip visible="true" template="#= category # - #= kendo.format('{0:P}', percentage) #"></tooltip> |
| 92 | + </kendo-chart> |
| 93 | +``` |
| 94 | +{% endif %} |
| 95 | + |
| 96 | + |
| 97 | + |
| 98 | +## Configuring the Labels Visibility |
| 99 | + |
| 100 | +You can show or hide the Donut Chart labels through the `Visible()` configuration method for the given series. |
| 101 | + |
| 102 | +```HtmlHelper |
| 103 | + .Series(series => |
| 104 | + { |
| 105 | + series.Donut(new dynamic[] {}) |
| 106 | + .Labels(labels => labels |
| 107 | + .Visible(true) |
| 108 | + ); |
| 109 | + }) |
| 110 | +``` |
| 111 | +{% if site.core %} |
| 112 | +```TagHelper |
| 113 | + <series-defaults type="ChartSeriesType.Donut"></series-defaults> |
| 114 | + <series> |
| 115 | + <series-item data='new dynamic[] {}'> |
| 116 | + <labels visible="true"></labels> |
| 117 | + </series-item> |
| 118 | + </series> |
| 119 | +``` |
| 120 | +{% endif %} |
| 121 | + |
| 122 | +## Configuring the Labels Alignment |
| 123 | + |
| 124 | +The Donut Chart allows you to configure the label alignment for the series through the `Align()` method. |
| 125 | + |
| 126 | +```HtmlHelper |
| 127 | + .Series(series => |
| 128 | + { |
| 129 | + series.Donut(new dynamic[] {}) |
| 130 | + .Labels(labels => labels |
| 131 | + .Align(ChartSeriesLabelsAlign.Circle) |
| 132 | + ); |
| 133 | + }) |
| 134 | +``` |
| 135 | +{% if site.core %} |
| 136 | +```TagHelper |
| 137 | + <series-defaults type="ChartSeriesType.Donut"></series-defaults> |
| 138 | + <series> |
| 139 | + <series-item data='new dynamic[] {}'> |
| 140 | + <labels align="ChartSeriesLabelsAlign.Circle"></labels> |
| 141 | + </series-item> |
| 142 | + </series> |
| 143 | +``` |
| 144 | +{% endif %} |
| 145 | + |
| 146 | +The Donut Chart supports two modes of label alignment: |
| 147 | + |
| 148 | +* `Circle`(default)—The labels are positioned in a circle around the Chart. |
| 149 | + |
| 150 | +  |
| 151 | +* `Column`—The labels are positioned in columns to the left and right of the Chart. |
| 152 | + |
| 153 | +  |
| 154 | + |
| 155 | + |
| 156 | +## Configuring the Effects Overlay |
| 157 | + |
| 158 | +Each segment has a transparent effect overlay that adds depth to the two-dimensional shape. The overlay transparent gradient is configurable through the `Overlay()` option. |
| 159 | + |
| 160 | +```HtmlHelper |
| 161 | + .Series(series => |
| 162 | + { |
| 163 | + series.Donut(new dynamic[] {}) |
| 164 | + .Overlay(o => o.Gradient(ChartSeriesGradient.None)); |
| 165 | + }) |
| 166 | +``` |
| 167 | +{% if site.core %} |
| 168 | +```TagHelper |
| 169 | + <series-defaults type="ChartSeriesType.Donut"></series-defaults> |
| 170 | + <series> |
| 171 | + <series-item data='new dynamic[] {}'> |
| 172 | + <overlay gradient="ChartSeriesGradient.None" /> |
| 173 | + </series-item> |
| 174 | + </series> |
| 175 | +``` |
| 176 | +{% endif %} |
| 177 | + |
| 178 | +The Donut Chart supports the following `ChartSeriesGradient` options: |
| 179 | + |
| 180 | +* (Default) `RoundedBevel` |
| 181 | + |
| 182 | +  |
| 183 | + |
| 184 | +* `SharpBevel` |
| 185 | + |
| 186 | +  |
| 187 | + |
| 188 | +* `None` |
| 189 | + |
| 190 | +  |
| 191 | + |
| 192 | + |
| 193 | +## See Also |
| 194 | + |
| 195 | +* [Basic Usage of the Donut Chart HtmlHelper for {{ site.framework }} (Demo)](https://demos.telerik.com/{{ site.platform }}/donut-charts/index) |
| 196 | +* [Data Binding Options for the Telerik UI for {{ site.framework }} Charts]({% slug htmlhelpers_charts_databinding_aspnetcore %}) |
| 197 | +* [Server-Side API](/api/chart) |
0 commit comments