Chart Plotting RadChartView with MySql Database

2 posts, 0 answers
  1. Hmingthanga
    Hmingthanga avatar
    1 posts
    Member since:
    Dec 2013

    Posted 04 Dec 2013 Link to this post

    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
  2. George
    Admin
    George avatar
    500 posts

    Posted 09 Dec 2013 Link to this post

    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 >>
  3. UI for WinForms is Visual Studio 2017 Ready
Back to Top