Bar Chart

Bar charts use horizontal tetragons to display information as bars. There are three types of bar chart, normal, stacked, and 100% stacked.

There are nine types of bar series available to create bar charts. Of these, the BarSeries, StackedBarSeries, and Stacked100PercentBarSeries are parent classes to two subclasses, one for date/time data and one of indexed data.

Normal X-Axis Y-Axis
BarSeries
DateTimeBarSeries NumericXAxis DateTimeYAxis
IndexedBarSeries NumericXAxis IndexedYAxis
Stacked
StackedBarSeries
DateTimeStackedBarSeries NumericXAxis DateTimeYAxis
IndexedStackedBarSeries NumericXAxis IndexedYAxis
100% Stacked
Stacked100PercentBarSeries
DateTime100PercentStackedBarSeries PercentageXAxis DateTimeYAxis
Indexed100PercentStackedBarSeries PercentageXAxis DateTimeYAxis

Normal

Normal bar charts create tetragons based on the data from a BarSeries. They use the DateTimeYAxis or IndexedYAxis as the y-axis (YAxis) and NumericXAxis as the x-axis (XAxis).

Figure 1. Normal Bar Chart

The following example uses an IndexedBarSeries to create a bar chart with indexed data.

// 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 bar series and add values to it
IndexedBarSeries barSeries1 = new IndexedBarSeries("Website A");
barSeries1.Values.Add(new float[] { 5, 7, 9, 6 });
IndexedBarSeries barSeries2 = new IndexedBarSeries("Website B");
barSeries2.Values.Add(new float[] { 4, 2, 5, 8 });
IndexedBarSeries barSeries3 = new IndexedBarSeries("Website C");
barSeries3.Values.Add(new float[] { 2, 4, 6, 9 });

// Create autogradient and assign it to series
AutoGradient autogradient1 = new AutoGradient(180f, CmykColor.Red, CmykColor.IndianRed);
barSeries1.Color = autogradient1;
AutoGradient autogradient2 = new AutoGradient(180f, CmykColor.Green, CmykColor.YellowGreen);
barSeries2.Color = autogradient2;
AutoGradient autogradient3 = new AutoGradient(180f, CmykColor.Blue, CmykColor.LightBlue);
barSeries3.Color = autogradient3;

// Add indexed bar series to the plot area
plotArea.Series.Add(barSeries1);
plotArea.Series.Add(barSeries2);
plotArea.Series.Add(barSeries3);

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

//Adding AxisLabels to the yAxis
barSeries1.YAxis.Labels.Add(new IndexedYAxisLabel("Q1", 0));
barSeries1.YAxis.Labels.Add(new IndexedYAxisLabel("Q2", 1));
barSeries1.YAxis.Labels.Add(new IndexedYAxisLabel("Q3", 2));
barSeries1.YAxis.Labels.Add(new IndexedYAxisLabel("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 bar series and add values to it
Dim MyBarSeries1 As New IndexedBarSeries("Website A")
MyBarSeries1.Values.Add(New Single() {5, 7, 9, 6})
Dim MyBarSeries2 As New IndexedBarSeries("Website B")
MyBarSeries2.Values.Add(New Single() {4, 2, 5, 8})
Dim MyBarSeries3 As New IndexedBarSeries("Website C")
MyBarSeries3.Values.Add(New Single() {2, 4, 6, 9})

' Create autogradient and assign it to series
Dim MyAutogradient1 As AutoGradient = New AutoGradient(180.0F, CmykColor.Red, CmykColor.IndianRed)
MyBarSeries1.Color = MyAutogradient1
Dim MyAutogradient2 As AutoGradient = New AutoGradient(180.0F, CmykColor.Green, CmykColor.YellowGreen)
MyBarSeries2.Color = MyAutogradient2
Dim MyAutogradient3 As AutoGradient = New AutoGradient(180.0F, CmykColor.Blue, CmykColor.LightBlue)
MyBarSeries3.Color = MyAutogradient3

' Add indexed bar series to the plot area
MyPlotArea.Series.Add(MyBarSeries1)
MyPlotArea.Series.Add(MyBarSeries2)
MyPlotArea.Series.Add(MyBarSeries3)

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

'Adding AxisLabels to the yAxis
MyBarSeries1.YAxis.Labels.Add(New IndexedYAxisLabel("Q1", 0))
MyBarSeries1.YAxis.Labels.Add(New IndexedYAxisLabel("Q2", 1))
MyBarSeries1.YAxis.Labels.Add(New IndexedYAxisLabel("Q3", 2))
MyBarSeries1.YAxis.Labels.Add(New IndexedYAxisLabel("Q4", 3))

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

Stacked

Stacked charts display related data, one on top of the other. They use DateTimeYAxis or IndexedYAxis as the y-axis (YAxis) based on the series and NumericXAxis as the x-axis (XAxis).

Figure 2. Stacked Bar Chart

The following example uses an IndexedStackSeries to create a bar chart based on indexed data.

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

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

// Create a Indexed Stacked Bar Series
IndexedStackedBarSeries barSeries = new IndexedStackedBarSeries();
// Add indexed stacked bar series elements to the Indexed Stacked Bar Series
barSeries.Add(seriesElement1);
barSeries.Add(seriesElement2);
barSeries.Add(seriesElement3);
//Add series to the plot area
plotArea.Series.Add(barSeries);

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

//Adding AxisLabels to the yaxis
barSeries.YAxis.Labels.Add(new IndexedYAxisLabel("Q1", 0));
barSeries.YAxis.Labels.Add(new IndexedYAxisLabel("Q2", 1));
barSeries.YAxis.Labels.Add(new IndexedYAxisLabel("Q3", 2));
barSeries.YAxis.Labels.Add(new IndexedYAxisLabel("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 chartdim 
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 bar series elements and add values to it
Dim MySeriesElement1 As New IndexedStackedBarSeriesElement("Website A")
MySeriesElement1.Values.Add(New Single() {5, 7, 9, 6})
Dim MySeriesElement2 As New IndexedStackedBarSeriesElement("Website B")
MySeriesElement2.Values.Add(New Single() {4, 2, 5, 8})
Dim MySeriesElement3 As New IndexedStackedBarSeriesElement("Website C")
MySeriesElement3.Values.Add(New Single() {2, 4, 6, 9})

' Create autogradient and assign it to series
Dim MyAutogradient1 As AutoGradient = New AutoGradient(180.0F, CmykColor.Red, CmykColor.IndianRed)
MySeriesElement1.Color = MyAutogradient1
Dim MyAutogradient2 As AutoGradient = New AutoGradient(180.0F, CmykColor.Green, CmykColor.YellowGreen)
MySeriesElement2.Color = MyAutogradient2
Dim MyAutogradient3 As AutoGradient = New AutoGradient(180.0F, CmykColor.Blue, CmykColor.LightBlue)
MySeriesElement3.Color = MyAutogradient3

' Create a Indexed Stacked Bar Series
Dim MyBarSeries As New IndexedStackedBarSeries()

' Add indexed stacked bar series elements to the Indexed Stacked Bar Series
MyBarSeries.Add(MySeriesElement1)
MyBarSeries.Add(MySeriesElement2)
MyBarSeries.Add(MySeriesElement3)

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

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

'Adding AxisLabels to the yaxis
MyBarSeries.YAxis.Labels.Add(New IndexedYAxisLabel("Q1", 0))
MyBarSeries.YAxis.Labels.Add(New IndexedYAxisLabel("Q2", 1))
MyBarSeries.YAxis.Labels.Add(New IndexedYAxisLabel("Q3", 2))
MyBarSeries.YAxis.Labels.Add(New IndexedYAxisLabel("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 the data is expressed as a percentage. These charts use DateTimeYAxis or IndexedYAxis as the y-axis (YAxis) based on the series and PercentageXAxis as the x-axis (XAxis).

Figure 3. Stacked 100% Bar Chart

The following example uses an Indexed100PercentStackedBarSeries to create a bar chart based on percentage indexed data.

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

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

// Create a Indexed 100% Stacked Bar Series
Indexed100PercentStackedBarSeries barSeries = new Indexed100PercentStackedBarSeries();
// Add SeriesElements to the Indexed 100% Stacked Bar Series
barSeries.Add(seriesElement1);
barSeries.Add(seriesElement2);
barSeries.Add(seriesElement3);
// Add series to the plot area
plotArea.Series.Add(barSeries);

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

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

' Create autogradient and assign it to series
Dim MyAutogradient1 As AutoGradient = New AutoGradient(180.0F, CmykColor.Red, CmykColor.IndianRed)
MySeriesElement1.Color = MyAutogradient1
Dim MyAutogradient2 As AutoGradient = New AutoGradient(180.0F, CmykColor.Green, CmykColor.YellowGreen)
MySeriesElement2.Color = MyAutogradient2
Dim MyAutogradient3 As AutoGradient = New AutoGradient(180.0F, CmykColor.Blue, CmykColor.LightBlue)
MySeriesElement3.Color = MyAutogradient3

' Create a Indexed 100% Stacked Bar Series
Dim MyBarSeries = New Indexed100PercentStackedBarSeries()
' Add SeriesElements to the Indexed 100% Stacked Bar Series
MyBarSeries.Add(MySeriesElement1)
MyBarSeries.Add(MySeriesElement2)
MyBarSeries.Add(MySeriesElement3)
' Add series to the plot area
MyPlotArea.Series.Add(MyBarSeries)

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

'Adding AxisLabels to the yaxis
MyBarSeries.YAxis.Labels.Add(New IndexedYAxisLabel("Q1", 0))
MyBarSeries.YAxis.Labels.Add(New IndexedYAxisLabel("Q2", 1))
MyBarSeries.YAxis.Labels.Add(New IndexedYAxisLabel("Q3", 2))
MyBarSeries.YAxis.Labels.Add(New IndexedYAxisLabel("Q4", 3))

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

In this topic