Chart / Charts / Chart Types / Pie / Pie Chart
In This Topic
    Pie Chart
    In This Topic

    A pie chart is a circular chart that represents portions of data as slices of pie. The size of each slice is proportional to its value relative to the total sum of all pie slice values. Pie charts are commonly used in business and charts to represent relative category sizes. The following images shows a typical pie chart:

     

     Creating a Pie Chart
    To create a pie chart you need to create an instance of the NPieChart type and add it to the chart surface. The following code shows how to create a pie chart containing one series with three slices:
    C#
    Copy Code
    // create a dock panel with label and chart
    NDockPanel dockPanel = new NDockPanel();
    chartView.Surface.Content = dockPanel;
    // create a docked label
    NLabel label = new NLabel();
    label.Text = "My First Pie Chart";
    label.Margins = new NMargins(10);
    label.Font = new NFont(NFontDescriptor.DefaultSansFamilyName, 12);
    label.TextFill = new NColorFill(NColor.Black);
    label.TextAlignment = ENContentAlignment.MiddleCenter;
    NDockLayout.SetDockArea(label, ENDockArea.Top);
    dockPanel.AddChild(label);
    // create a new cartesian chart
    NPieChart pieChart = new NPieChart();
    pieChart.Margins = new NMargins(10);
    NDockLayout.SetDockArea(pieChart, ENDockArea.Center);
    dockPanel.AddChild(pieChart);
    // create a bar series
    NPieSeries pieSeries = new NPieSeries();
    NPieDataPoint slice1 = new NPieDataPoint(10);
    slice1.Fill = new NColorFill(NColor.Red);
    pieSeries.DataPoints.Add(slice1);
    NPieDataPoint slice2 = new NPieDataPoint(20);
    slice2.Fill = new NColorFill(NColor.Green);
    pieSeries.DataPoints.Add(slice2);
    NPieDataPoint slice3 = new NPieDataPoint(30);
    slice3.Fill = new NColorFill(NColor.Blue);
    pieSeries.DataPoints.Add(slice3);
    pieChart.Series.Add(pieSeries);
    
    See Also