Area Chart

Area charts use polygons to display information using the Chart class. A chart is defined by the data series added to the chart; no property identifies a chart as a specific type. There are three area chart types: normal, stacked, and 100% stacked.

Area Chart Series
Normal DateTimeAreaSeries, IndexedAreaSeries
Stacked DateTimeStackedAreaSeries, IndexedStackedAreaSeries
100% Stacked DateTime100PercentStackedAreaSeries, Indexed100PercentStackedAreaSeries

Normal

Normal area charts create polygons using data from a DateTimeAreaSeries or an IndexedAreaSeries. The chart places the values series values on either a DateTimeXAxis or an IndexedXAxis as the x-axis and a NumericYAxis as the y-axis.

Area Normal Figure 1. Normal Area Chart

The following example illustrates a normal area chart with an IndexedAreaSeries as the data series.

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

// Create a chart
Chart chart = new Chart(0, 0, 400, 230);
// Create a plot area
PlotArea plotArea = chart.PrimaryPlotArea;

// Create header titles and add it to the chart
Title title1 = new Title("Website Visitors");
Title title2 = new Title("Year - 2007");
chart.HeaderTitles.Add(title1);
chart.HeaderTitles.Add(title2);                       

// Create indexed area series and add values to it
IndexedAreaSeries areaSeries1 = new IndexedAreaSeries("Website A");
areaSeries1.Values.Add(new float[]{5, 7, 9, 6});

// Create autogradient and assign it to series
AutoGradient autogradient1 = new AutoGradient(90f, CmykColor.Red, CmykColor.IndianRed);
areaSeries1.Color = autogradient1;

// Add indexed area series to the plot area
plotArea.Series.Add(areaSeries1);

// Create a title and add it to the YAxis
Title lTitle = new Title("Visitors (in millions)");
areaSeries1.YAxis.Titles.Add(lTitle);  

//Adding AxisLabels to the XAxis
areaSeries1.XAxis.Labels.Add(new IndexedXAxisLabel("Q1", 0));
areaSeries1.XAxis.Labels.Add(new IndexedXAxisLabel("Q2", 1));
areaSeries1.XAxis.Labels.Add(new IndexedXAxisLabel("Q3", 2));
areaSeries1.XAxis.Labels.Add(new IndexedXAxisLabel("Q4", 3));

// 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
MyDocument.Pages.Add(MyPage)

' Create a MyChart
Dim MyChart As New Chart(0, 0, 400, 230)
' Create a plot area
Dim MyPlotArea As PlotArea = MyChart.PrimaryPlotArea

' Create header titles and add it to the MyChart
Dim MyTitle1 As New Title("Website Visitors")
Dim MyTitle2 As New Title("Year - 2007")
MyChart.HeaderTitles.Add(MyTitle1)
MyChart.HeaderTitles.Add(MyTitle2)

' Create indexed area series and add values to it
Dim MyAreaSeries1 As New IndexedAreaSeries("Website A")
MyAreaSeries1.Values.Add(New Single() {5, 7, 9, 6})

' Add autogradient colors to series
Dim MyAutogradient1 As AutoGradient = New AutoGradient(90.0F, CmykColor.Red, CmykColor.IndianRed)
MyAreaSeries1.Color = MyAutogradient1

' Add indexed area series to the plot area
MyPlotArea.Series.Add(MyAreaSeries1)

' Create a title and add it to the YAxis
Dim MylTitle As New Title("Visitors (in millions)")
MyAreaSeries1.YAxis.Titles.Add(MylTitle)

'Adding AxisLabels to the XAxis
MyAreaSeries1.XAxis.Labels.Add(New IndexedXAxisLabel("Q1", 0))
MyAreaSeries1.XAxis.Labels.Add(New IndexedXAxisLabel("Q2", 1))
MyAreaSeries1.XAxis.Labels.Add(New IndexedXAxisLabel("Q3", 2))
MyAreaSeries1.XAxis.Labels.Add(New IndexedXAxisLabel("Q4", 3))

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

Stacked

Stacked area charts display related data on top of one another and use data from either a DateTimeStackedAreaSeries or an IndexedStackedAreaSeries. The data series places the values using a DateTimeXAxis or an IndexedXAxis as the x-axis. The x-axis values use each series as the category (i.e., quarter) and data values for each series (i.e., visitors) as the y-axis using a NumericYAxis.

Figure 2. Stacked Area Chart

The following example illustrates creating a stacked chart.

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

// Create a chart
Chart chart = new Chart(0, 0, 400, 230);
// Create a plot area
PlotArea plotArea = chart.PrimaryPlotArea;

// Create header titles and add it to the chart
Title title1 = new Title("Website Visitors");
Title title2 = new Title("Year - 2007");
chart.HeaderTitles.Add(title1);
chart.HeaderTitles.Add(title2);

// Create indexed stacked area series elements and add values to it
IndexedStackedAreaSeriesElement seriesElement1 = new IndexedStackedAreaSeriesElement("Website A");
seriesElement1.Values.Add(new float[] { 5, 7, 9, 6 });
IndexedStackedAreaSeriesElement seriesElement2 = new IndexedStackedAreaSeriesElement("Website B");
seriesElement2.Values.Add(new float[] { 4, 2, 5, 8 });
IndexedStackedAreaSeriesElement seriesElement3 = new IndexedStackedAreaSeriesElement("Website C");
seriesElement3.Values.Add(new float[] { 2, 4, 6, 9 });

// Create autogradient and assign it to series
AutoGradient autogradient1 = new AutoGradient(90f, CmykColor.Red, CmykColor.IndianRed);
seriesElement1.Color = autogradient1;
AutoGradient autogradient2 = new AutoGradient(90f, CmykColor.Green, CmykColor.YellowGreen);
seriesElement2.Color = autogradient2;
AutoGradient autogradient3 = new AutoGradient(120f, CmykColor.Blue, CmykColor.LightBlue);
seriesElement3.Color = autogradient3;

// Create a Indexed Stacked Area Series
IndexedStackedAreaSeries areaSeries = new IndexedStackedAreaSeries();

// Add indexed stacked area series elements to the Indexed Stacked Area Series
areaSeries.Add(seriesElement1);
areaSeries.Add(seriesElement2);
areaSeries.Add(seriesElement3);

// Add series to the plot area
plotArea.Series.Add(areaSeries);

// Create a title and add it to the YAxis
Title lTitle = new Title("Visitors (in millions)");
areaSeries.YAxis.Titles.Add(lTitle);

//Adding AxisLabels to the XAxis
areaSeries.XAxis.Labels.Add(new IndexedXAxisLabel("Q1", 0));
areaSeries.XAxis.Labels.Add(new IndexedXAxisLabel("Q2", 1));
areaSeries.XAxis.Labels.Add(new IndexedXAxisLabel("Q3", 2));
areaSeries.XAxis.Labels.Add(new IndexedXAxisLabel("Q4", 3));

// 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()
MyDocument.Pages.Add(MyPage)

' Create a MyChart
Dim MyChart As New Chart(0, 0, 400, 230)

' Create a plot area
Dim MyPlotArea As PlotArea = MyChart.PrimaryPlotArea

' Create header titles and add it to the MyChart
Dim MyTitle1 As New Title("Website Visitors")
Dim MyTitle2 As New Title("Year - 2007")
MyChart.HeaderTitles.Add(MyTitle1)
MyChart.HeaderTitles.Add(MyTitle2)

'Create indexed stacked are series elements and add values to it
Dim MySeriesElement1 As New IndexedStackedAreaSeriesElement("Website A")
MySeriesElement1.Values.Add(New Single() {5, 7, 9, 6})
Dim MySeriesElement2 As New IndexedStackedAreaSeriesElement("Website B")
MySeriesElement2.Values.Add(New Single() {4, 2, 5, 8})
Dim MySeriesElement3 As New IndexedStackedAreaSeriesElement("Website C")
MySeriesElement3.Values.Add(New Single() {2, 4, 6, 9})

' Add autogradient colors to series
Dim MyAutogradient1 As AutoGradient = New AutoGradient(90.0F, CmykColor.Red, CmykColor.IndianRed)
MySeriesElement1.Color = MyAutogradient1
Dim MyAutogradient2 As AutoGradient = New AutoGradient(90.0F, CmykColor.Green, CmykColor.YellowGreen)
MySeriesElement2.Color = MyAutogradient2
Dim MyAutogradient3 As AutoGradient = New AutoGradient(120.0F, CmykColor.Blue, CmykColor.LightBlue)
MySeriesElement3.Color = MyAutogradient3

' Create a Indexed Stacked Area Series
Dim MyAreaSeries As New IndexedStackedAreaSeries()

' Add indexed stacked area series elements to the Indexed Stacked Area Series
MyAreaSeries.Add(MySeriesElement1)
MyAreaSeries.Add(MySeriesElement2)
MyAreaSeries.Add(MySeriesElement3)

' Add series to the plot area
MyPlotArea.Series.Add(MyAreaSeries)

' Create a title and add it to the YAxis
Dim MylTitle As New Title("Visitors (in millions)")
MyAreaSeries.YAxis.Titles.Add(MylTitle)

'Adding AxisLabels to the XAxis
MyAreaSeries.XAxis.Labels.Add(New IndexedXAxisLabel("Q1", 0))
MyAreaSeries.XAxis.Labels.Add(New IndexedXAxisLabel("Q2", 1))
MyAreaSeries.XAxis.Labels.Add(New IndexedXAxisLabel("Q3", 2))
MyAreaSeries.XAxis.Labels.Add(New IndexedXAxisLabel("Q4", 3))

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

100% Stacked

100% stacked area charts are similar to stacked charts but express data as a percentage. These charts use either a DateTime100PercentStackedAreaSeries or an Indexed100PercentStackedAreaSeries. The data places the series along a DateTimeXAxis or an IndexedXAxis for the x-axis and a PercentageYAxis for the y-axis.

Figure 3. Stacked 100% Area Chart

The following example illustrates creating a 100% stacked chart.

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

// Create a chart
Chart chart = new Chart(0, 0, 400, 230);
// Create a plot area
PlotArea plotArea = chart.PrimaryPlotArea;

// Create header titles and add it to the chart
Title title1 = new Title("Website Visitors");
Title title2 = new Title("Year - 2007");
chart.HeaderTitles.Add(title1);
chart.HeaderTitles.Add(title2);

// Create a indexed 100% stacked area series elements and add values to it
Indexed100PercentStackedAreaSeriesElement seriesElement1 = new Indexed100PercentStackedAreaSeriesElement("Website A");
seriesElement1.Values.Add(new float[] { 5, 7, 9, 6 });
Indexed100PercentStackedAreaSeriesElement seriesElement2 = new Indexed100PercentStackedAreaSeriesElement("Website B");
seriesElement2.Values.Add(new float[] { 4, 2, 5, 8 });
Indexed100PercentStackedAreaSeriesElement seriesElement3 = new Indexed100PercentStackedAreaSeriesElement("Website C");
seriesElement3.Values.Add(new float[] { 2, 4, 6, 9 });

// Create autogradient and assign it to series
AutoGradient autogradient1 = new AutoGradient(90f, CmykColor.Red, CmykColor.IndianRed);
seriesElement1.Color = autogradient1;
AutoGradient autogradient2 = new AutoGradient(90f, CmykColor.Green, CmykColor.YellowGreen);
seriesElement2.Color = autogradient2;
AutoGradient autogradient3 = new AutoGradient(120f, CmykColor.Blue, CmykColor.LightBlue);
seriesElement3.Color = autogradient3;

// Create a Indexed 100% Stacked Area Series
Indexed100PercentStackedAreaSeries areaSeries = new Indexed100PercentStackedAreaSeries();

// Add indexed 100% stacked area series elements to the Indexed 100% Stacked Area Series
areaSeries.Add(seriesElement1);
areaSeries.Add(seriesElement2);
areaSeries.Add(seriesElement3);

// Add series to the plot area
plotArea.Series.Add(areaSeries);

// Create a title and add it to the yAxis
Title lTitle = new Title("Visitors (in millions)");
areaSeries.YAxis.Titles.Add(lTitle);

//Adding AxisLabels to the XAxis
areaSeries.XAxis.Labels.Add(new IndexedXAxisLabel("Q1", 0));
areaSeries.XAxis.Labels.Add(new IndexedXAxisLabel("Q2", 1));
areaSeries.XAxis.Labels.Add(new IndexedXAxisLabel("Q3", 2));
areaSeries.XAxis.Labels.Add(new IndexedXAxisLabel("Q4", 3));

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

' Create a Page and add it to the MyDocument
Dim MyPage As New Page()
MyDocument.Pages.Add(MyPage)

' Create a MyChart
Dim MyChart As New Chart(0, 0, 400, 230)

' Create a plot area
Dim MyPlotArea As PlotArea = MyChart.PrimaryPlotArea

' Create header titles and add it to the MyChart
Dim MyTitle1 As New Title("Website Visitors")
Dim MyTitle2 As New Title("Year - 2007")
MyChart.HeaderTitles.Add(MyTitle1)
MyChart.HeaderTitles.Add(MyTitle2)

' Create a indexed 100% stacked area series elements and add values to it
Dim MySeriesElement1 As New Indexed100PercentStackedAreaSeriesElement("Website A")
MySeriesElement1.Values.Add(New Single() {5, 7, 9, 6})
Dim MySeriesElement2 As New Indexed100PercentStackedAreaSeriesElement("Website B")
MySeriesElement2.Values.Add(New Single() {4, 2, 5, 8})
Dim MySeriesElement3 As New Indexed100PercentStackedAreaSeriesElement("Website C")
MySeriesElement3.Values.Add(New Single() {2, 4, 6, 9})

' Add autogradient colors to series
Dim MyAutogradient1 As AutoGradient = New AutoGradient(90.0F, CmykColor.Red, CmykColor.IndianRed)
MySeriesElement1.Color = MyAutogradient1
Dim MyAutogradient2 As AutoGradient = New AutoGradient(90.0F, CmykColor.Green, CmykColor.YellowGreen)
MySeriesElement2.Color = MyAutogradient2
Dim MyAutogradient3 As AutoGradient = New AutoGradient(120.0F, CmykColor.Blue, CmykColor.LightBlue)
MySeriesElement3.Color = MyAutogradient3

' Create a Indexed 100% Stacked Area Series
Dim MyAreaSeries As New Indexed100PercentStackedAreaSeries()

' Add indexed 100% stacked area series elements to the Indexed 100% Stacked Area Series
MyAreaSeries.Add(MySeriesElement1)
MyAreaSeries.Add(MySeriesElement2)
MyAreaSeries.Add(MySeriesElement3)

' Add series to the plot area
MyPlotArea.Series.Add(MyAreaSeries)

' Create a title and add it to the yAxis
Dim MylTitle As New Title("Visitors (in millions)")
MyAreaSeries.YAxis.Titles.Add(MylTitle)

'Adding AxisLabels to the XAxis
MyAreaSeries.XAxis.Labels.Add(New IndexedXAxisLabel("Q1", 0))
MyAreaSeries.XAxis.Labels.Add(New IndexedXAxisLabel("Q2", 1))
MyAreaSeries.XAxis.Labels.Add(New IndexedXAxisLabel("Q3", 2))
MyAreaSeries.XAxis.Labels.Add(New IndexedXAxisLabel("Q4", 3))

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

In this topic