Anda di halaman 1dari 7

Imports System

Imports PdfSharp.Drawing

Namespace PdfSharp.Charting.Demo
'/ <summary>
'/ Defines some chart samples.
'/ </summary>
Public Class ChartSamples
Public Shared Function LineChart() As Chart
Dim chart As Chart = New Chart(ChartType.Line)
Dim series As Series = chart.SeriesCollection.AddSeries()
series.Name ="Series 1"
Dim Double() As series.Add(New
{
1, 5, -3, 20, 11
}
)

series = chart.SeriesCollection.AddSeries()
series.Name ="Series 2"
Dim Double() As series.Add(New
{
22, 4, 12, 8, 12
}
)

series = chart.SeriesCollection.AddSeries()
series.Name ="Series 3"
Dim Double() As series.Add(New
{
12, 14, -3, 18, 1
}
)

chart.XAxis.MajorTickMark = TickMarkType.Outside
chart.XAxis.Title.Caption = "X-Axis"

chart.YAxis.MajorTickMark = TickMarkType.Outside
chart.YAxis.Title.Caption = "Y-Axis"
chart.YAxis.HasMajorGridlines = True

chart.PlotArea.LineFormat.Color = XColors.DarkGray
chart.PlotArea.LineFormat.Width = 1
chart.PlotArea.LineFormat.Visible = True

chart.Legend.Docking = DockingType.Bottom
chart.Legend.LineFormat.Visible = True

Dim xseries As XSeries = chart.XValues.AddXSeries()


xseries.Add("A", "B", "C", "D", "E", "F")

Return chart
End Function

Public Shared Function ColumnChart() As Chart


Dim chart As Chart = New Chart(ChartType.Column2D)
Dim series As Series = chart.SeriesCollection.AddSeries()
series.Name = "Series 1"
Dim Double() As series.Add(New
{
1, 5, -3, 20, 11
}
)

series = chart.SeriesCollection.AddSeries()
series.Name = "Series 2"
Dim Double() As series.Add(New
{
22, 4, 12, 8, 12
}
)

series = chart.SeriesCollection.AddSeries()
series.Name = "Series 3"
Dim Double() As series.Add(New
{
12, 14, 2, 18, 1
}
)

series = chart.SeriesCollection.AddSeries()
series.Name = "Series 4"
Dim Double() As series.Add(New
{
17, 13, 10, 9, 15
}
)

chart.XAxis.TickLabels.Format = "00"
chart.XAxis.MajorTickMark = TickMarkType.Outside
chart.XAxis.Title.Caption = "X-Axis"

chart.YAxis.MajorTickMark = TickMarkType.Outside
chart.YAxis.HasMajorGridlines = True

chart.PlotArea.LineFormat.Color = XColors.DarkGray
chart.PlotArea.LineFormat.Width = 1
chart.PlotArea.LineFormat.Visible = True

chart.Legend.Docking = DockingType.Right

chart.DataLabel.Type = DataLabelType.Value
chart.DataLabel.Position = DataLabelPosition.OutsideEnd

Return chart
End Function

Public Shared Function ColumnStackedChart() As Chart


Dim chart As Chart = New Chart(ChartType.ColumnStacked2D)
Dim series As Series = chart.SeriesCollection.AddSeries()
series.Name = "Series 1"
Dim Double() As series.Add(New
{
1, 5, -3, 20, 11
}
)

series = chart.SeriesCollection.AddSeries()
series.Name = "Series 2"
Dim Double() As series.Add(New
{
22, 4, 12, 8, 12
}
)

series = chart.SeriesCollection.AddSeries()
series.Name = "Series 3"
Dim Double() As series.Add(New
{
12, 14, 2, 18, 1
}
)

series = chart.SeriesCollection.AddSeries()
series.Name = "Series 4"
Dim Double() As series.Add(New
{
17, 13, 10, 9, 15
}
)

chart.XAxis.TickLabels.Format = "00"
chart.XAxis.MajorTickMark = TickMarkType.Outside
chart.XAxis.Title.Caption = "X-Axis"

chart.YAxis.MajorTickMark = TickMarkType.Outside
chart.YAxis.HasMajorGridlines = True

chart.PlotArea.LineFormat.Color = XColors.DarkGray
chart.PlotArea.LineFormat.Width = 1
chart.PlotArea.LineFormat.Visible = True

chart.Legend.Docking = DockingType.Right

chart.DataLabel.Type = DataLabelType.Value
chart.DataLabel.Position = DataLabelPosition.Center

Return chart
End Function

Public Shared Function BarChart() As Chart


Dim chart As Chart = New Chart(ChartType.Bar2D)
Dim series As Series = chart.SeriesCollection.AddSeries()
series.Name = "Series 1"
Dim Double() As series.Add(New
{
1, 5, -3, 20, 11
}
)

series = chart.SeriesCollection.AddSeries()
series.Name = "Series 2"
Dim Double() As series.Add(New
{
22, 4, 12, 8, 12
}
)
series = chart.SeriesCollection.AddSeries()
series.Name = "Series 3"
Dim Double() As series.Add(New
{
12, 14, 2, 18, 1
}
)

series = chart.SeriesCollection.AddSeries()
series.Name = "Series 4"
Dim Double() As series.Add(New
{
17, 13, 10, 9, 15
}
)

chart.XAxis.MajorTickMark = TickMarkType.Outside
chart.XAxis.Title.Caption = "X-Axis"

chart.YAxis.MajorTickMark = TickMarkType.Outside
chart.YAxis.HasMajorGridlines = True

chart.PlotArea.LineFormat.Color = XColors.DarkGray
chart.PlotArea.LineFormat.Width = 1
chart.PlotArea.LineFormat.Visible = True

chart.Legend.Docking = DockingType.Right

chart.DataLabel.Type = DataLabelType.Value
chart.DataLabel.Position = DataLabelPosition.InsideEnd

Return chart
End Function

Public Shared Function BarStackedChart() As Chart


Dim chart As Chart = New Chart(ChartType.BarStacked2D)
Dim series As Series = chart.SeriesCollection.AddSeries()
series.Name = "Series 1"
Dim Double() As series.Add(New
{
1, 5, -3, 20, 11
}
)

series = chart.SeriesCollection.AddSeries()
series.Name = "Series 2"
Dim Double() As series.Add(New
{
22, 4, 12, 8, 12
}
)

series = chart.SeriesCollection.AddSeries()
series.Name = "Series 3"
Dim Double() As series.Add(New
{
12, 14, 2, 18, 1
}
)

series = chart.SeriesCollection.AddSeries()
series.Name = "Series 4"
Dim Double() As series.Add(New
{
17, 13, 10, 9, 15
}
)

chart.XAxis.MajorTickMark = TickMarkType.Outside
chart.XAxis.Title.Caption = "X-Axis"

chart.YAxis.MajorTickMark = TickMarkType.Outside
chart.YAxis.HasMajorGridlines = True

chart.PlotArea.LineFormat.Color = XColors.DarkGray
chart.PlotArea.LineFormat.Width = 1
chart.PlotArea.LineFormat.Visible = True

chart.Legend.Docking = DockingType.Right

chart.DataLabel.Type = DataLabelType.Value
chart.DataLabel.Position = DataLabelPosition.Center

Return chart
End Function

Public Shared Function AreaChart() As Chart


Dim chart As Chart = New Chart(ChartType.Area2D)
Dim series As Series = chart.SeriesCollection.AddSeries()
Dim Double() As series.Add(New
{
31, 9, 15, 28, 13
}
)

series = chart.SeriesCollection.AddSeries()
Dim Double() As series.Add(New
{
22, 7, 12, 21, 12
}
)

series = chart.SeriesCollection.AddSeries()
Dim Double() As series.Add(New
{
16, 5, 3, 20, 11
}
)

chart.XAxis.TickLabels.Format = "00"
chart.XAxis.MajorTickMark = TickMarkType.Outside
chart.XAxis.Title.Caption = "X-Axis"

chart.YAxis.MajorTickMark = TickMarkType.Outside
chart.YAxis.HasMajorGridlines = True

chart.PlotArea.LineFormat.Color = XColors.DarkGray
chart.PlotArea.LineFormat.Width = 1
chart.PlotArea.LineFormat.Visible = True

chart.Legend.Docking = DockingType.Top

Return chart
End Function

Public Shared Function PieChart() As Chart


Dim chart As Chart = New Chart(ChartType.Pie2D)
Dim series As Series = chart.SeriesCollection.AddSeries()
Dim Double() As series.Add(New
{
1, 5, 11, -3, 20
}
)

Dim xseries As XSeries = chart.XValues.AddXSeries()


xseries.Add("Production", "Lab", "Licenses", "Taxes", "Insurances")
chart.Legend.Docking = DockingType.Right

chart.DataLabel.Type = DataLabelType.Percent
chart.DataLabel.Position = DataLabelPosition.OutsideEnd

Return chart
End Function

Public Shared Function PieExplodedChart() As Chart


Dim chart As Chart = New Chart(ChartType.PieExploded2D)
Dim series As Series = chart.SeriesCollection.AddSeries()
Dim Double() As series.Add(New
{
1, 17, 45, 5, 3, 20, 11, 23, 8, 19, 34, 56, 23, 45
}
)

chart.Legend.Docking = DockingType.Left
chart.DataLabel.Type = DataLabelType.Percent
chart.DataLabel.Position = DataLabelPosition.Center

Return chart
End Function

Public Shared Function CombinationChart() As Chart


Dim chart As Chart = New Chart()
Dim series As Series = chart.SeriesCollection.AddSeries()
series.ChartType = ChartType.Column2D
Dim Double() As series.Add(New
{
1, 17, 45, 5, 3, 20, 11, 23, 8, 19
}
)
series.HasDataLabel = True

series = chart.SeriesCollection.AddSeries()
series.ChartType = ChartType.Line
Dim Double() As series.Add(New
{
41, 7, 5, 45, 13, 10, 21, 13, 18, 9
}
)

Dim xseries As XSeries = chart.XValues.AddXSeries()


xseries.Add("A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M",
"N")

chart.XAxis.MajorTickMark = TickMarkType.Outside
chart.XAxis.Title.Caption = "X-Axis"

chart.YAxis.MajorTickMark = TickMarkType.Outside
chart.YAxis.HasMajorGridlines = True

chart.PlotArea.LineFormat.Color = XColors.DarkGray
chart.PlotArea.LineFormat.Width = 1
chart.PlotArea.LineFormat.Visible = True

chart.Legend.Docking = DockingType.Left
chart.Legend.LineFormat.Visible = True

Return chart
End Function
End Class
End Namespace

'----------------------------------------------------------------
' Converted from C# to VB .NET using CSharpToVBConverter(1.2).
' Developed by: Kamal Patel (http://www.KamalPatel.net)
'----------------------------------------------------------------

'==============================================================================
PdfDocument doc = new PdfDocument();
PdfPage page = doc.AddPage();
page.Size = PdfSharp.PageSize.A4;
XFont font = new XFont("Verdana", 20, XFontStyle.Bold);
XGraphics gfx = XGraphics.FromPdfPage(page);

Chart chart = LineChart();


ChartFrame chartFrame = new ChartFrame();
chartFrame.Location = new XPoint(30, 30);
chartFrame.Size = new XSize(500, 200);
chartFrame.Add(chart);
chartFrame.Draw(gfx);

'==============================================================================