Example E1047
Visible to All Users

How to create a Doughnut chart

Files to look at:

The following example demonstrates how to create a Doughnut chart at runtime.

Note that this series view type is associated with the Simple Diagram type, and you should cast your diagram object to this type, in order to access its specific options.

Starting from v14.1, text pattern properties (AxisLabel.TextPattern, SeriesLabelBase.TextPattern, SeriesBase.LegendTextPattern) have been introduced instead of point options. Text pattern properties simplify text customization of series labels, axis labels and legend items (when the SeriesViewColorEachSupportBase.ColorEach mode is enabled).

Does this example address your development requirements/objectives?

(you will be redirected to DevExpress.com to submit your response)

Example Code

Series_DoughnutChart/Form1.cs(vb)
C#
using System; using System.Windows.Forms; using DevExpress.XtraCharts; namespace Series_DoughnutChart { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { // Create a new chart. ChartControl DoughnutChart = new ChartControl(); // Create a doughnut series. Series series1 = new Series("Series 1", ViewType.Doughnut); // Populate the series with points. series1.Points.Add(new SeriesPoint("Russia", 17.0752)); series1.Points.Add(new SeriesPoint("Canada", 9.98467)); series1.Points.Add(new SeriesPoint("USA", 9.63142)); series1.Points.Add(new SeriesPoint("China", 9.59696)); series1.Points.Add(new SeriesPoint("Brazil", 8.511965)); series1.Points.Add(new SeriesPoint("Australia", 7.68685)); series1.Points.Add(new SeriesPoint("India", 3.28759)); series1.Points.Add(new SeriesPoint("Others", 81.2)); // Add the series to the chart. DoughnutChart.Series.Add(series1); // Specify the text pattern of series labels. series1.Label.TextPattern = "{A}: {VP:P0}"; // Specify how series points are sorted. series1.SeriesPointsSorting = SortingMode.Ascending; series1.SeriesPointsSortingKey = SeriesPointKey.Argument; // Specify the behavior of series labels. ((DoughnutSeriesLabel)series1.Label).Position = PieSeriesLabelPosition.TwoColumns; ((DoughnutSeriesLabel)series1.Label).ResolveOverlappingMode = ResolveOverlappingMode.Default; ((DoughnutSeriesLabel)series1.Label).ResolveOverlappingMinIndent = 5; // Adjust the view-type-specific options of the series. ((DoughnutSeriesView)series1.View).ExplodedPoints.Add(series1.Points[0]); ((DoughnutSeriesView)series1.View).ExplodedDistancePercentage = 30; // Access the diagram's options. ((SimpleDiagram)DoughnutChart.Diagram).Dimension = 2; // Add a title to the chart and hide the legend. ChartTitle chartTitle1 = new ChartTitle(); chartTitle1.Text = "2D Doughnut Chart"; DoughnutChart.Titles.Add(chartTitle1); DoughnutChart.Legend.Visibility = DevExpress.Utils.DefaultBoolean.False; // Add the chart to the form. DoughnutChart.Dock = DockStyle.Fill; this.Controls.Add(DoughnutChart); } } }

Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.