locked
How to link a Pie chart to column from database and show total of each of the same item in that column RRS feed

  • Question

  • I am new to programming so sorry for the noob question. Ok so what i would like to do is the following, I have a form with a pie chart that I want to link to a database and have each section of the pie chart show data from a specific column and show the total number of the same items in that column. Example the Action, Drama, Animation for each of the section and then show the total number of each in that same column. I know how to link the database but unsure of the code for the example I gave. any help I thank you for! I also know the code would go between the While loop but not sure of the code


    James franklin

    Friday, May 30, 2014 4:33 AM

Answers

  • Hi,

    You need to add Series(ChartType is Pie) for Chart control and set XValueMember and YValueMembers property based on your column.

    For example:

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal _
            e As System.EventArgs) Handles MyBase.Load
            Dim dt As New DataTable()
            dt.Columns.Add("Status")
            dt.Columns.Add("Total")
    
            dt.Rows.Add("Success", 34)
            dt.Rows.Add("Missing", 2)
            dt.Rows.Add("Failed", 10)
    
            Chart1.DataSource = dt
            Chart1.Series("Series1").XValueMember = "Status"
            Chart1.Series("Series1").YValueMembers = "Total"
            Chart1.DataBind()
        End Sub

    Screenshot:


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Proposed as answer by IssueKiller Monday, June 2, 2014 7:18 AM
    • Marked as answer by Jafranklin77 Monday, June 2, 2014 10:42 AM
    Monday, June 2, 2014 3:24 AM
  • Hi

    Try this

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal _
            e As System.EventArgs) Handles MyBase.Load
            Dim dt As New DataTable()
            dt.Columns.Add("Status")
            dt.Columns.Add("Total")
    
            dt.Rows.Add("Success", 34)
            dt.Rows.Add("Missing", 2)
            dt.Rows.Add("Failed", 10)
    
            Chart1.DataSource = dt
            Chart1.Series("Series1").XValueMember = "Status"
            Chart1.Series("Series1").YValueMembers = "Total"
            Chart1.Series("Series1").Label = "#Total{N2}"
            Chart1.DataBind()
        End Sub

    Ref

    http://betterdashboards.wordpress.com/2009/02/04/display-percentages-on-a-pie-chart/

    http://msdn.microsoft.com/en-us/library/dd489231(v=vs.110).aspx


    Shridhar J Joshi Thanks a lot


    Monday, June 2, 2014 5:47 AM
  • Thank you for the help. I just have one other question is it possible to also show the Count on the chart as well. for example have the 34, 2, & 10 show next to or somewhere for each section of the echart?

    James franklin

    Sure, like this:

    ......
    Chart1.DataSource = dt
    Chart1.Series("Series1").XValueMember = "Status"
    Chart1.Series("Series1").YValueMembers = "Total"
    Chart1.Series("Series1").Label = "#AXISLABEL #VALY"
    Chart1.DataBind()

    Screenshot:


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by Jafranklin77 Monday, June 2, 2014 10:42 AM
    Monday, June 2, 2014 7:31 AM

All replies

  • Hi,

    You need to add Series(ChartType is Pie) for Chart control and set XValueMember and YValueMembers property based on your column.

    For example:

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal _
            e As System.EventArgs) Handles MyBase.Load
            Dim dt As New DataTable()
            dt.Columns.Add("Status")
            dt.Columns.Add("Total")
    
            dt.Rows.Add("Success", 34)
            dt.Rows.Add("Missing", 2)
            dt.Rows.Add("Failed", 10)
    
            Chart1.DataSource = dt
            Chart1.Series("Series1").XValueMember = "Status"
            Chart1.Series("Series1").YValueMembers = "Total"
            Chart1.DataBind()
        End Sub

    Screenshot:


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Proposed as answer by IssueKiller Monday, June 2, 2014 7:18 AM
    • Marked as answer by Jafranklin77 Monday, June 2, 2014 10:42 AM
    Monday, June 2, 2014 3:24 AM
  • Thank you for the help. I just have one other question is it possible to also show the Count on the chart as well. for example have the 34, 2, & 10 show next to or somewhere for each section of the echart?

    James franklin

    Monday, June 2, 2014 5:28 AM
  • Hi

    Try this

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal _
            e As System.EventArgs) Handles MyBase.Load
            Dim dt As New DataTable()
            dt.Columns.Add("Status")
            dt.Columns.Add("Total")
    
            dt.Rows.Add("Success", 34)
            dt.Rows.Add("Missing", 2)
            dt.Rows.Add("Failed", 10)
    
            Chart1.DataSource = dt
            Chart1.Series("Series1").XValueMember = "Status"
            Chart1.Series("Series1").YValueMembers = "Total"
            Chart1.Series("Series1").Label = "#Total{N2}"
            Chart1.DataBind()
        End Sub

    Ref

    http://betterdashboards.wordpress.com/2009/02/04/display-percentages-on-a-pie-chart/

    http://msdn.microsoft.com/en-us/library/dd489231(v=vs.110).aspx


    Shridhar J Joshi Thanks a lot


    Monday, June 2, 2014 5:47 AM
  • Thank you for the help. I just have one other question is it possible to also show the Count on the chart as well. for example have the 34, 2, & 10 show next to or somewhere for each section of the echart?

    James franklin

    Sure, like this:

    ......
    Chart1.DataSource = dt
    Chart1.Series("Series1").XValueMember = "Status"
    Chart1.Series("Series1").YValueMembers = "Total"
    Chart1.Series("Series1").Label = "#AXISLABEL #VALY"
    Chart1.DataBind()

    Screenshot:


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by Jafranklin77 Monday, June 2, 2014 10:42 AM
    Monday, June 2, 2014 7:31 AM