Tuesday, July 5, 2011

CHART CONTROL IN VB.NET


Imports System.Windows.Forms.DataVisualization.Charting


Public Class frmChart
Dim dtTest As New DataTable
Dim iRowCount As Integer = 0
Dim iPageCounter As Integer = 0
Dim bIschart As Boolean = False
Private Sub frmChart_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load


End Sub



Private Sub btnShow_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnShow.Click

dtTest.Columns.Clear()
dtTest.Rows.Clear()
dtTest.Columns.Add("Name")
dtTest.Columns.Add("Marks")




'dttest = modCons.dtChart.Copy()
iRowCount = modCons.dtChart.Rows.Count
If (iRowCount > 40) Then
For i As Integer = 0 To 39
dtTest.Rows.Add(modCons.dtChart.Rows(i)("Name").ToString(), modCons.dtChart.Rows(i)("Marks").ToString())
Next
If (bIschart = False) Then
Chart1.Series.Add("Name")
With Chart1.Series(0)
' .Name = "Candidate Graph"
.Font = New Font("Arial", 8, FontStyle.Italic)
.BackGradientStyle = GradientStyle.TopBottom
.Color = Color.Magenta
.BackSecondaryColor = Color.Purple
.IsValueShownAsLabel = True
.LabelBackColor = Color.Transparent
.LabelForeColor = Color.Purple
.Points.DataBind(dtTest.DefaultView, "Name", "Name", Nothing)
.CustomProperties = "DrawingStyle = Cylinder ,PixelPointWidth = 26"
End With
With Chart1.Series(1)
.Font = New Font("Arial", 8, FontStyle.Italic)
.BackGradientStyle = GradientStyle.TopBottom
.Color = Color.Aqua
.BackSecondaryColor = Color.Blue
.IsValueShownAsLabel = True
.SmartLabelStyle.CalloutStyle = LabelCalloutStyle.Box
.LabelBackColor = Color.Transparent
.LabelForeColor = Color.Blue
.Points.DataBindY(dtTest.DefaultView, "Marks")
.CustomProperties = "DrawingStyle = Cylinder ,PixelPointWidth = 26"

End With
With Chart1.ChartAreas(0)
.AxisX.Interval = 1
.AxisX.LabelStyle.Angle = -90
.AxisX.Title = "Name"
.AxisY.Title = "Marks"
End With

Dim strip As New StripLine
strip.BackColor = Color.LightSalmon
strip.IntervalOffset = 50
strip.StripWidth = 2
Chart1.ChartAreas(0).AxisY.StripLines.Add(strip)
' Chart1.Dispose()
bIschart = True


End If
Else




For i As Integer = 0 To modCons.dtChart.Rows.Count - 1
dtTest.Rows.Add(modCons.dtChart.Rows(i)("Name").ToString(), modCons.dtChart.Rows(i)("Marks").ToString())
Next
If (bIschart = False) Then
Chart1.Series.Add("Name")
With Chart1.Series(0)
' .Name = "Candidate Graph"
.Font = New Font("Arial", 8, FontStyle.Italic)
.BackGradientStyle = GradientStyle.TopBottom
.Color = Color.Magenta
.BackSecondaryColor = Color.Purple
.IsValueShownAsLabel = True
.LabelBackColor = Color.Transparent
.LabelForeColor = Color.Purple
.Points.DataBind(dtTest.DefaultView, "Name", "Name", Nothing)
.CustomProperties = "DrawingStyle = Cylinder ,PixelPointWidth = 26"
End With
With Chart1.Series(1)
.Font = New Font("Arial", 8, FontStyle.Italic)
.BackGradientStyle = GradientStyle.TopBottom
.Color = Color.Aqua
.BackSecondaryColor = Color.Blue
.IsValueShownAsLabel = True
.SmartLabelStyle.CalloutStyle = LabelCalloutStyle.Box
.LabelBackColor = Color.Transparent
.LabelForeColor = Color.Blue
.Points.DataBindY(dtTest.DefaultView, "Marks")
.CustomProperties = "DrawingStyle = Cylinder ,PixelPointWidth = 26"

End With
With Chart1.ChartAreas(0)
.AxisX.Interval = 1
.AxisX.LabelStyle.Angle = -90
.AxisX.Title = "Name"
.AxisY.Title = "Marks"
End With

Dim strip As New StripLine
strip.BackColor = Color.LightSalmon
strip.IntervalOffset = 50
strip.StripWidth = 2
Chart1.ChartAreas(0).AxisY.StripLines.Add(strip)
' Chart1.Dispose()
bIschart = True
btnFwd.Enabled = False
btnPrv.Enabled = False


End If


End If


End Sub

Private Sub btnPrv_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrv.Click
' Chart1.Dispose()
iPageCounter -= 1
dtTest.Columns.Clear()
dtTest.Rows.Clear()
dtTest.Columns.Add("Name")
dtTest.Columns.Add("Marks")
Dim iEndCounter As Integer = (40 * iPageCounter) + 40

If (iEndCounter > modCons.dtChart.Rows.Count - 1) Then
iEndCounter = modCons.dtChart.Rows.Count - 1
btnFwd.Enabled = False
Else
btnFwd.Enabled = True
End If
Dim j As Integer = iRowCount - 40
For k As Integer = (40 * iPageCounter) + 1 To iEndCounter
dtTest.Rows.Add(modCons.dtChart.Rows(k)("Name").ToString(), modCons.dtChart.Rows(k)("Marks").ToString())
Next
If (bIschart = False) Then


Chart1.Series.Add("Name")
With Chart1.Series(0)
.Name = "Candidate Graph"
.Font = New Font("Arial", 8, FontStyle.Italic)
.BackGradientStyle = GradientStyle.TopBottom
.Color = Color.Magenta
.BackSecondaryColor = Color.Purple
.IsValueShownAsLabel = True
.LabelBackColor = Color.Transparent
.LabelForeColor = Color.Purple
.Points.DataBind(dtTest.DefaultView, "Name", "Name", Nothing)
.CustomProperties = "DrawingStyle = Cylinder ,PixelPointWidth = 26"
End With
With Chart1.Series(1)
.Font = New Font("Arial", 8, FontStyle.Italic)
.BackGradientStyle = GradientStyle.TopBottom
.Color = Color.Aqua
.BackSecondaryColor = Color.Blue
.IsValueShownAsLabel = True
.SmartLabelStyle.CalloutStyle = LabelCalloutStyle.Box
.LabelBackColor = Color.Transparent
.LabelForeColor = Color.Blue
.Points.DataBindY(dtTest.DefaultView, "Marks")
.CustomProperties = "DrawingStyle = Cylinder ,PixelPointWidth = 26"

End With
With Chart1.ChartAreas(0)
.AxisX.Interval = 1
.AxisX.LabelStyle.Angle = -90
.AxisX.Title = "Name"
.AxisY.Title = "Marks"
End With

Dim strip As New StripLine
strip.BackColor = Color.LightSalmon
strip.IntervalOffset = 50
strip.StripWidth = 2
Chart1.ChartAreas(0).AxisY.StripLines.Add(strip)
' Chart1.Dispose()

Else
With Chart1.Series(0)
.Name = "Candidate Graph"
.Font = New Font("Arial", 8, FontStyle.Italic)
.BackGradientStyle = GradientStyle.TopBottom
.Color = Color.Magenta
.BackSecondaryColor = Color.Purple
.IsValueShownAsLabel = True
.LabelBackColor = Color.Transparent
.LabelForeColor = Color.Purple
.Points.DataBind(dtTest.DefaultView, "Name", "Name", Nothing)
.CustomProperties = "DrawingStyle = Cylinder ,PixelPointWidth = 26"
End With
With Chart1.Series(1)
.Font = New Font("Arial", 8, FontStyle.Italic)
.BackGradientStyle = GradientStyle.TopBottom
.Color = Color.Aqua
.BackSecondaryColor = Color.Blue
.IsValueShownAsLabel = True
.SmartLabelStyle.CalloutStyle = LabelCalloutStyle.Box
.LabelBackColor = Color.Transparent
.LabelForeColor = Color.Blue
.Points.DataBindY(dtTest.DefaultView, "Marks")
.CustomProperties = "DrawingStyle = Cylinder ,PixelPointWidth = 26"

End With
With Chart1.ChartAreas(0)
.AxisX.Interval = 1
.AxisX.LabelStyle.Angle = -90
.AxisX.Title = "Name"
.AxisY.Title = "Marks"
End With

Dim strip As New StripLine
strip.BackColor = Color.LightSalmon
strip.IntervalOffset = 50
strip.StripWidth = 2
Chart1.ChartAreas(0).AxisY.StripLines.Add(strip)
If (iPageCounter = 0) Then
btnPrv.Enabled = False
Else
btnPrv.Enabled = True
End If
End If

End Sub

Private Sub btnFwd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFwd.Click
' Chart1.Dispose()
iPageCounter += 1
dtTest.Columns.Clear()
dtTest.Rows.Clear()
dtTest.Columns.Add("Name")
dtTest.Columns.Add("Marks")
Dim iEndCounter As Integer = (40 * iPageCounter) + 40

If (iEndCounter > modCons.dtChart.Rows.Count - 1) Then
iEndCounter = modCons.dtChart.Rows.Count - 1
btnFwd.Enabled = False
Else
btnFwd.Enabled = True
End If
Dim j As Integer = iRowCount - 40
For k As Integer = (40 * iPageCounter) + 1 To iEndCounter
dtTest.Rows.Add(modCons.dtChart.Rows(k)("Name").ToString(), modCons.dtChart.Rows(k)("Marks").ToString())
Next
If (bIschart = False) Then


Chart1.Series.Add("Name")
With Chart1.Series(0)
.Name = "Candidate Graph"
.Font = New Font("Arial", 8, FontStyle.Italic)
.BackGradientStyle = GradientStyle.TopBottom
.Color = Color.Magenta
.BackSecondaryColor = Color.Purple
.IsValueShownAsLabel = True
.LabelBackColor = Color.Transparent
.LabelForeColor = Color.Purple
.Points.DataBind(dtTest.DefaultView, "Name", "Name", Nothing)
.CustomProperties = "DrawingStyle = Cylinder ,PixelPointWidth = 26"
End With
With Chart1.Series(1)
.Font = New Font("Arial", 8, FontStyle.Italic)
.BackGradientStyle = GradientStyle.TopBottom
.Color = Color.Aqua
.BackSecondaryColor = Color.Blue
.IsValueShownAsLabel = True
.SmartLabelStyle.CalloutStyle = LabelCalloutStyle.Box
.LabelBackColor = Color.Transparent
.LabelForeColor = Color.Blue
.Points.DataBindY(dtTest.DefaultView, "Marks")
.CustomProperties = "DrawingStyle = Cylinder ,PixelPointWidth = 26"

End With
With Chart1.ChartAreas(0)
.AxisX.Interval = 1
.AxisX.LabelStyle.Angle = -90
.AxisX.Title = "Name"
.AxisY.Title = "Marks"
End With

Dim strip As New StripLine
strip.BackColor = Color.LightSalmon
strip.IntervalOffset = 50
strip.StripWidth = 2
Chart1.ChartAreas(0).AxisY.StripLines.Add(strip)
' Chart1.Dispose()

Else
With Chart1.Series(0)
.Name = "Candidate Graph"
.Font = New Font("Arial", 8, FontStyle.Italic)
.BackGradientStyle = GradientStyle.TopBottom
.Color = Color.Magenta
.BackSecondaryColor = Color.Purple
.IsValueShownAsLabel = True
.LabelBackColor = Color.Transparent
.LabelForeColor = Color.Purple
.Points.DataBind(dtTest.DefaultView, "Name", "Name", Nothing)
.CustomProperties = "DrawingStyle = Cylinder ,PixelPointWidth = 26"
End With
With Chart1.Series(1)
.Font = New Font("Arial", 8, FontStyle.Italic)
.BackGradientStyle = GradientStyle.TopBottom
.Color = Color.Aqua
.BackSecondaryColor = Color.Blue
.IsValueShownAsLabel = True
.SmartLabelStyle.CalloutStyle = LabelCalloutStyle.Box
.LabelBackColor = Color.Transparent
.LabelForeColor = Color.Blue
.Points.DataBindY(dtTest.DefaultView, "Marks")
.CustomProperties = "DrawingStyle = Cylinder ,PixelPointWidth = 26"

End With
With Chart1.ChartAreas(0)
.AxisX.Interval = 1
.AxisX.LabelStyle.Angle = -90
.AxisX.Title = "Name"
.AxisY.Title = "Marks"
End With

Dim strip As New StripLine
strip.BackColor = Color.LightSalmon
strip.IntervalOffset = 50
strip.StripWidth = 2
Chart1.ChartAreas(0).AxisY.StripLines.Add(strip)

If (iPageCounter = 0) Then
btnPrv.Enabled = False
Else
btnPrv.Enabled = True
End If
End If

End Sub

Private Sub btnPrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrint.Click
PrintDocument1.Print()
End Sub
End Class

No comments:

Post a Comment