[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


ASP.net assign data to a chart

Posted on 2011-10-23
Medium Priority
Last Modified: 2012-08-14

I use the code below to populate GridView in ASP.net 4 VB.net.
I need to populate a chart with the same data. What code would I use to do this?
Protected Sub Button_View_Results_Click(sender As Object, e As EventArgs) Handles Button_View_Results.Click

        If Me.Label_Reviewer.Text = "" Then
            Me.Label_Please_LogIn.Text = "Please log in first!"
            Exit Sub
        End If
        Me.Label_Please_LogIn.Text = ""

        'If Not IsPostBack Then

        Dim sSQL As String
        sSQL = "SELECT Answers.Survey, Answers.Category, Avg(Answers.Score) * 20 AS [Result Percentage] "
        sSQL = sSQL & "FROM Answers "
        sSQL = sSQL & "GROUP BY Answers.Survey, Answers.Category, Answers.ReviewerID "
        sSQL = sSQL & "HAVING (((Answers.ReviewerID)='" & Me.Label_Reviewer.Text & "'))"
        'sSQL = sSQL & "HAVING (((Answers.ReviewerID)='R'))"

        Dim queryString2 As String = sSQL

        ' Run the query and bind the resulting DataSet
        ' to the GridView control.
        Dim ds2 As DataSet = GetData(queryString2) 'test connection
        If (ds2.Tables.Count > 0) Then

            Me.GridView1.DataSource = ds2


            'Me.Label_Error1.Text = "Unable to connect to the database. " & Err.Description

        End If

        ' End If
    End Sub

Open in new window

Question by:Murray Brown
LVL 39

Accepted Solution

Pratima Pharande earned 1000 total points
ID: 37016283

Assisted Solution

Rahul_Gade earned 1000 total points
ID: 37016765
A Quick sample using X and Y source, your query has 3 sources, so you will need to identify 2 of them for chart.

DataTable dt = new DataTable();
 dt.Rows.Add("Physics", 95);
 dt.Rows.Add("Maths", 82);
 dt.Rows.Add("English", 88);
 Chart1.DataSource = dt;
 Chart1.Series["Series1"].XValueMember = "Subject";
 Chart1.Series["Series1"].YValueMembers = "Marks";


Author Closing Comment

by:Murray Brown
ID: 37059318
thanks for the help

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses
Course of the Month19 days, 11 hours left to enroll

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question