This is a migrated thread and some comments may be shown as answers.

Chart Plotting RadChartView with MySql Database

1 Answer 150 Views
ChartView
This is a migrated thread and some comments may be shown as answers.
Hmingthanga
Top achievements
Rank 1
Hmingthanga asked on 04 Dec 2013, 12:07 PM
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

1 Answer, 1 is accepted

Sort by
0
George
Telerik team
answered on 09 Dec 2013, 10:10 AM
Hello Hmingthanga,

Thank you for writing.

We highly value your contribution and effort, and I am sure that someone will find this information useful. I encourage you to post your solution in our CodeLibrary section. After you submit your post, we will review it.

I am updating your Telerik Points for your effort.

Let us know if you have any questions.

Regards,
George
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WINFORMS.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
Tags
ChartView
Asked by
Hmingthanga
Top achievements
Rank 1
Answers by
George
Telerik team
Share this question
or