Pie Chart

Pie Charts use a circle to display the information. The circle is divided into different parts depending on the data. Each part displays the related piece of information.


Figure 1 - An example 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)

In this topic