Pie Chart

Pie charts use a circle to display information. The circle is divided into different parts depending on the data. Each part displays the related piece of information. Recall that you use a PieSeries to create a pie chart.

Figure 1. An example pie chart

PieSeries

The PieSeries is what creates a pie chart. To create a pie chart you first create a Chart instance, its PlotArea, and then the PieSeries.

Properties

Property Description
BorderColor Gets or sets the Color object.
BorderWidth Gets or sets the BorderWidth of the PieSeries.
DataLabel Gets or sets the ScalarDataLabel object to use for the data label of the Pie series. This is the default data label for the series.
DataLabelPosition Gets or sets ScalarDataLabelPosition enumeration that specifies the display position of the data label.
DrawBehindAxis Gets or sets the position of the Series either below or above the axis. By default it is true. (Inherited from SeriesBase)
Elements Gets the PieSeriesElementList object contained in the PieSeries.
Height Gets the height of the PieSeries.
Label Gets or sets the SeriesLabel object to use for the name of the PieSeries.
Legend Gets or sets the Legend object of the PlotAreaElement. (Inherited from PlotAreaElement)
PercentageFormat Gets or sets the format to use for the percentage of the ScalarDataLabel object.
PlotArea Gets the PlotArea object of the PlotAreaElement. (Inherited from PlotAreaElement)
Radius Gets or sets the radius.
StartAngle Gets or sets the StartAngle.
ValueFormat Gets or sets the format to use for the value of the ScalarDataLabel object.
Width Gets the width.
X Gets the X coordinate.
XOffset Gets or sets the XOffset.
Y Gets the Y coordinate.
YOffset Gets or sets the YOffset.

Example

The following code illustrates creating a pie chart.

// Create a PDF Document
Document document = new Document();
// Create a Page and add it to the document
Page page = new Page(PageSize.A4, PageOrientation.Landscape);
document.Pages.Add(page);

// Create a chart
Chart chart = new Chart(0, 0, 700, 400);
// Add a plot area to the chart
PlotArea plotArea = chart.PlotAreas.Add(50, 50, 300, 300);

// Create the Header titles and add it to the chart
Title tTitle = new Title("Website Viewers (in millions)");
Title tTitle1 = new Title("Year 2007");
chart.HeaderTitles.Add(tTitle);
chart.HeaderTitles.Add(tTitle1);

// Create autogradient colors
AutoGradient autogradient1 = new AutoGradient(90f, CmykColor.Red, CmykColor.IndianRed);
AutoGradient autogradient2 = new AutoGradient(90f, CmykColor.Green, CmykColor.YellowGreen);
AutoGradient autogradient3 = new AutoGradient(90f, CmykColor.Blue, CmykColor.LightBlue);

// Create a scalar datalabel
ScalarDataLabel da = new ScalarDataLabel(true, false, false);
// Create a pie series 
PieSeries pieSeries = new PieSeries();
// Set scalar datalabel to the pie series
pieSeries.DataLabel = da;            
// Add series to the plot area
plotArea.Series.Add(pieSeries);

//Add pie series elements to the pie series
pieSeries.Elements.Add(27, "Website A");
pieSeries.Elements.Add(19, "Website B");
pieSeries.Elements.Add(21, "Website C");

// Assign autogradient colors to series elements
pieSeries.Elements[0].Color = autogradient1;
pieSeries.Elements[1].Color = autogradient2;
pieSeries.Elements[2].Color = autogradient3;

// Add the chart to the page
page.Elements.Add(chart);
// Save the pdf
document.Draw(pdfFilePath);        
' Create a PDF Document
Dim MyDocument As New Document()

' Create a Page and add it to the MyDocument
Dim MyPage As New Page(PageSize.A4, PageOrientation.Landscape)
MyDocument.Pages.Add(MyPage)

' Create a MyChart
Dim MyChart = New Chart(0, 0, 700, 400)
' Add a plot area to the MyChart
Dim MyPlotArea As PlotArea = MyChart.PlotAreas.Add(50, 50, 300, 300)

' Create the Header titles and add it to the MyChart
Dim MytTitle As New Title("Website Viewers (in millions)")
Dim MytTitle1 As New Title("Year 2007")
MyChart.HeaderTitles.Add(MytTitle)
MyChart.HeaderTitles.Add(MytTitle1)

' Create autogradient colors 
Dim MyAutogradient1 As AutoGradient = New AutoGradient(90.0F, CmykColor.Red, CmykColor.IndianRed)
Dim MyAutogradient2 As AutoGradient = New AutoGradient(90.0F, CmykColor.Green, CmykColor.YellowGreen)
Dim MyAutogradient3 As AutoGradient = New AutoGradient(90.0F, CmykColor.Blue, CmykColor.LightBlue)

' Create a scalar datalabel
Dim Myda As ScalarDataLabel = New ScalarDataLabel(True, False, False)
' Create a pie series 
Dim MyPieSeries As New PieSeries()
' Set scalar datalabel to the pie series
MyPieSeries.DataLabel = Myda
' Add series to the plot area
MyPlotArea.Series.Add(MyPieSeries)

'Add pie series elements to the pie series
MyPieSeries.Elements.Add(27, "Website A")
MyPieSeries.Elements.Add(19, "Website B")
MyPieSeries.Elements.Add(21, "Website C")

' Assign autogradient colors to series elements
MyPieSeries.Elements(0).Color = MyAutogradient1
MyPieSeries.Elements(1).Color = MyAutogradient2
MyPieSeries.Elements(2).Color = MyAutogradient3

' Add the MyChart to the MyPage
MyPage.Elements.Add(MyChart)
' Save the pdf
MyDocument.Draw(pdfFilePath)

Refer to the PieSeries API documentation for a complete example.

In this topic