Line Chart

Lines are used to display information in Line Charts. There are three different types, normal, stacked, and 100% Stacked.

Normal

Normal Line charts create lines based on the data. They use DateTimeXAxis or IndexedXAxis as the XAxis based on the series and NumericYAxis as the YAxis.


Figure 1 - Normal Line 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 line series and add values to it
IndexedLineSeries lineSeries1 = new IndexedLineSeries("Website A");
lineSeries1.Values.Add(new float[] { 5, 7, 9, 6 });
IndexedLineSeries lineSeries2 = new IndexedLineSeries("Website B");
lineSeries2.Values.Add(new float[] { 4, 2, 5, 8 });
IndexedLineSeries lineSeries3 = new IndexedLineSeries("Website C");
lineSeries3.Values.Add(new float[] { 2, 4, 6, 9 });

// Add indexed line series to the plot area
plotArea.Series.Add(lineSeries1);
plotArea.Series.Add(lineSeries2);
plotArea.Series.Add(lineSeries3);

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

//Adding AxisLabels to the XAxis
lineSeries1.XAxis.Labels.Add(new IndexedXAxisLabel("Q1", 0));
lineSeries1.XAxis.Labels.Add(new IndexedXAxisLabel("Q2", 1));
lineSeries1.XAxis.Labels.Add(new IndexedXAxisLabel("Q3", 2));
lineSeries1.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 a indexed line series and add values to it
Dim MyLineSeries1 As New IndexedLineSeries("Website A")
MyLineSeries1.Values.Add(New Single() {5, 7, 9, 6})
Dim MyLineSeries2 As New IndexedLineSeries("Website B")
MyLineSeries2.Values.Add(New Single() {4, 2, 5, 8})
Dim MyLineSeries3 As New IndexedLineSeries("Website C")
MyLineSeries3.Values.Add(New Single() {2, 4, 6, 9})

' Add indexed line series to the plot area
MyPlotArea.Series.Add(MyLineSeries1)
MyPlotArea.Series.Add(MyLineSeries2)
MyPlotArea.Series.Add(MyLineSeries3)

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

'Adding AxisLabels to the XAxis
MyLineSeries1.XAxis.Labels.Add(New IndexedXAxisLabel("Q1", 0))
MyLineSeries1.XAxis.Labels.Add(New IndexedXAxisLabel("Q2", 1))
MyLineSeries1.XAxis.Labels.Add(New IndexedXAxisLabel("Q3", 2))
MyLineSeries1.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 charts show related data, one on top of the other. They use DateTimeXAxis or IndexedXAxis as the XAxis based on the series and NumericYAxis as the YAxis.


Figure 2 - Stacked Line 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 stacked line series elements and add values to it
IndexedStackedLineSeriesElement seriesElement1 = new IndexedStackedLineSeriesElement("Website A");
seriesElement1.Values.Add(new float[] { 5, 7, 9, 6 });
IndexedStackedLineSeriesElement seriesElement2 = new IndexedStackedLineSeriesElement("Website B");
seriesElement2.Values.Add(new float[] { 4, 2, 5, 8 });
IndexedStackedLineSeriesElement seriesElement3 = new IndexedStackedLineSeriesElement("Website C");
seriesElement3.Values.Add(new float[] { 2, 4, 6, 9 });

// Create a Indexed Stacked Line Series
IndexedStackedLineSeries lineSeries = new IndexedStackedLineSeries();
// Add indexed stacked line series elements to the Indexed Stacked Line Series
lineSeries.Add(seriesElement1);
lineSeries.Add(seriesElement2);
lineSeries.Add(seriesElement3);

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

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

//Adding AxisLabels to the XAxis
lineSeries.XAxis.Labels.Add(new IndexedXAxisLabel("Q1", 0));
lineSeries.XAxis.Labels.Add(new IndexedXAxisLabel("Q2", 1));
lineSeries.XAxis.Labels.Add(new IndexedXAxisLabel("Q3", 2));
lineSeries.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 = 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 stacked line series elements and add values to it
Dim MySeriesElement1 As New IndexedStackedLineSeriesElement("Website A")
MySeriesElement1.Values.Add(New Single() {5, 7, 9, 6})
Dim MySeriesElement2 As New IndexedStackedLineSeriesElement("Website B")
MySeriesElement2.Values.Add(New Single() {4, 2, 5, 8})
Dim MySeriesElement3 As New IndexedStackedLineSeriesElement("Website C")
MySeriesElement3.Values.Add(New Single() {2, 4, 6, 9})

' Create a Indexed Stacked Line Series
Dim MylineSeries As New IndexedStackedLineSeries()

' Add indexed stacked line series elements to the Indexed Stacked Line Series
MylineSeries.Add(MySeriesElement1)
MylineSeries.Add(MySeriesElement2)
MylineSeries.Add(MySeriesElement3)

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

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

'Adding AxisLabels to the XAxis
MylineSeries.XAxis.Labels.Add(New IndexedXAxisLabel("Q1", 0))
MylineSeries.XAxis.Labels.Add(New IndexedXAxisLabel("Q2", 1))
MylineSeries.XAxis.Labels.Add(New IndexedXAxisLabel("Q3", 2))
MylineSeries.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 charts are similar to stacked charts, but here the data is expressed as a percentage. They use DateTimeXAxis or IndexedXAxis as the XAxis based on the series and PercentageYAxis as the YAxis.


Figure 3 - Stacked 100% Line 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 100% line series elements and add values to it
Indexed100PercentStackedLineSeriesElement seriesElement1 = new Indexed100PercentStackedLineSeriesElement("Website A");
seriesElement1.Values.Add(new float[] { 5, 7, 9, 6 });
Indexed100PercentStackedLineSeriesElement seriesElement2 = new Indexed100PercentStackedLineSeriesElement("Website B");
seriesElement2.Values.Add(new float[] { 4, 2, 5, 8 });
Indexed100PercentStackedLineSeriesElement seriesElement3 = new Indexed100PercentStackedLineSeriesElement("Website C");
seriesElement3.Values.Add(new float[] { 2, 4, 6, 9 });

// Create a Indexed 100% Stacked Line Series
Indexed100PercentStackedLineSeries lineSeries = new Indexed100PercentStackedLineSeries();
// Add indexed 100% line series elements to the Indexed 100% Stacked Line Series
lineSeries.Add(seriesElement1);
lineSeries.Add(seriesElement2);
lineSeries.Add(seriesElement3);
// Add the series to the plot area
plotArea.Series.Add(lineSeries);

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

//Adding AxisLabels to the XAxis
lineSeries.XAxis.Labels.Add(new IndexedXAxisLabel("Q1", 0));
lineSeries.XAxis.Labels.Add(new IndexedXAxisLabel("Q2", 1));
lineSeries.XAxis.Labels.Add(new IndexedXAxisLabel("Q3", 2));
lineSeries.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 100% line series elements and add values to it
Dim MySeriesElement1 As New Indexed100PercentStackedLineSeriesElement("Website A")
MySeriesElement1.Values.Add(New Single() {5, 7, 9, 6})
Dim MySeriesElement2 As New Indexed100PercentStackedLineSeriesElement("Website B")
MySeriesElement2.Values.Add(New Single() {4, 2, 5, 8})
Dim MySeriesElement3 As New Indexed100PercentStackedLineSeriesElement("Website C")
MySeriesElement3.Values.Add(New Single() {2, 4, 6, 9})

' Create a Indexed 100% Stacked Line Series
Dim MylineSeries As New Indexed100PercentStackedLineSeries()
'Add indexed 100% line series elements to the Indexed 100% Stacked Line Series
MylineSeries.Add(MySeriesElement1)
MylineSeries.Add(MySeriesElement2)
MylineSeries.Add(MySeriesElement3)
' Add the series to the plot area
MyPlotArea.Series.Add(MylineSeries)

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

'Adding AxisLabels to the XAxis
MylineSeries.XAxis.Labels.Add(New IndexedXAxisLabel("Q1", 0))
MylineSeries.XAxis.Labels.Add(New IndexedXAxisLabel("Q2", 1))
MylineSeries.XAxis.Labels.Add(New IndexedXAxisLabel("Q3", 2))
MylineSeries.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