Dear Reader,
I would like to share a sample code "How to populate RadChartView using Sql, Oledb or MySql Database in WinForm (VB.NET)".
I've been searching for this sample in RadChartView documentation but can't find it anywhere. Here to anyone who is having the same problem.
MySQL Database Table Looks like:
| id | Namess | Ages | Benefits |
-------------------------------------
| 1 | John | 16 | 51 |
-------------------------------------
| 2 | Jake | 22 | 60 |
-------------------------------------
| 3 | Miley | 30 | 15 |
-------------------------------------
| 4 | Oggy | 24 | 25 |
-------------------------------------
| 5 | Piggy | 12 | 22 |
-------------------------------------
The VB.NET Code Goes Like this:
Imports
Telerik.WinControls.UI
Imports
MySql.Data.MySqlClient
Imports
Telerik.Charting
Public
Class
RadForm2
Private
Sub
RadForm2_Load(sender
As
Object
, e
As
EventArgs)
Handles
MyBase
.Load
Me
.RadChartView1.Area.View.Palette = KnownPalette.Metro
' Me.RadChartView1.ThemeName = "TelerikMetro"
Me
.RadChartView1.AreaType = ChartAreaType.Cartesian
Dim
sarea
As
CartesianArea =
Me
.RadChartView1.GetArea(Of CartesianArea)()
Dim
sgrid
As
CartesianGrid = sarea.GetGrid(Of CartesianGrid)()
sarea.ShowGrid =
True
sgrid.DrawHorizontalFills =
True
sgrid.BorderDashStyle = System.Drawing.Drawing2D.DashStyle.DashDot
Dim
connetionString2
As
String
Dim
oledbCnn2
As
New
MySqlConnection
Dim
oledbCmd2
As
New
MySqlCommand
Dim
sql2
As
String
connetionString2 = (
"Data Source=localhost;user id=root;database=testss;"
)
sql2 =
"Select * from tabll"
oledbCnn2 =
New
MySqlConnection(connetionString2)
Try
oledbCnn2.Open()
oledbCmd2 =
New
MySqlCommand(sql2, oledbCnn2)
Dim
oledbReader2
As
MySqlDataReader = oledbCmd2.ExecuteReader()
With
oledbReader2
Dim
lineSeria
As
New
LineSeries()
RadChartView1.Series.Add(lineSeria)
lineSeria.ValueMember =
"Ages"
lineSeria.CategoryMember =
"Namess"
lineSeria.DataSource = oledbReader2
End
With
oledbReader2.Close()
oledbCmd2.Dispose()
oledbCnn2.Close()
Catch
ex
As
Exception
MsgBox(
"Can not open connection ! "
)
End
Try
Try
oledbCnn2.Open()
oledbCmd2 =
New
MySqlCommand(sql2, oledbCnn2)
Dim
oledbReader3
As
MySqlDataReader = oledbCmd2.ExecuteReader()
With
oledbReader3
Dim
lineSeria
As
New
LineSeries()
RadChartView1.Series.Add(lineSeria)
lineSeria.ValueMember =
"Benefits"
lineSeria.CategoryMember =
"Namess"
lineSeria.DataSource = oledbReader3
End
With
oledbReader3.Close()
oledbCmd2.Dispose()
oledbCnn2.Close()
Catch
ex
As
Exception
MsgBox(
"Can not open connection ! "
)
End
Try
End
Sub
End
Class
Hope You Enjoy!
Regards