Solved

ASP.net VB.net Chart

Posted on 2013-06-10
2
366 Views
Last Modified: 2013-06-14
Hi

The following image shows the data and chart representing that data, which are generated from the code further done. I am trying to represent the numbers 30,23,23,24 with the
corresponding labels L1,L2,L3,L4 on the one axis. What have I done wrong?


1
   Sub oLoad()
        Try


            Me.Chart1.ChartAreas(0).AxisX.Interval = 1
            Me.Chart1.ChartAreas(0).AxisY.Maximum = 100



            If Me.lblSelectedItems.Text = "" Then
                Me.Label_View_Error.Text = "Please select at least one Test!"
                Exit Sub
            End If


            Dim tSQL, tSQLc As String 'Used for totals
            tSQL = "Select * From Answers"
            tSQLc = "Select * From Answers"

            Dim oSurv As String 'Test
            Dim oRev As String = Me.Label_Reviewer.Text 'Reviewer
            Dim oCompID As String = Me.Label_Company.Text 'Company


            ' Run the query and bind the resulting DataSet
            ' to the GridView control.

            Dim ds1 As DataSet = GetData(tSQL) 'test connection
            Dim ds1c As DataSet = GetData(tSQLc)
   

            '-------questions-------------------
            Dim qds1 As DataSet = GetData(tSQL)


            '------------------------------------

            If (ds1.Tables.Count > 0) Then

                If chkIncludeQuestions.Checked = True Then
                    Me.GridView1.DataSource = qds1
                Else
                    Me.GridView1.DataSource = ds1
                End If

                Me.GridView1.DataBind()



                Chart1.Series("MyCategories").XValueMember = "Test"      ' remember that the series is defined in the chart markup
                Chart1.Series("MyCategories").YValueMembers = "L1,L2,R1,R2"
                Chart1.DataSource = ds1c
                Chart1.DataBind()




            Else

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

            End If
        Catch ex As Exception
            Response.Write(ex.Message)
        End Try
    End Sub

    Function GetData(ByVal queryString As String) As DataSet

        ' Retrieve the connection string stored in the Web.config file.
        'Dim connectionString As String = ConfigurationManager.ConnectionStrings("PSQL").ConnectionString
        'Dim myConnection As SqlConnection = New SqlConnection("server=196.220.43.xxx;database=test")
        Dim cs As String = ConfigurationManager.ConnectionStrings("Tests_conn").ConnectionString
        Dim myConnection As SqlConnection = New SqlConnection(cs)

        Dim ds As New DataSet()

        Try

            ' Connect to the database and run the query.
            'Dim connection As New SqlConnection(connectionString)
            'Dim adapter As New SqlDataAdapter(queryString, Connection)
            Dim adapter As New SqlDataAdapter(queryString, myConnection)
            ' Fill the DataSet.
            Adapter.Fill(ds)


        Catch ex As Exception

            ' The connection failed. Display an error message.
            Me.Label_Error1.Text = "Unable to connect to the database." & Err.Description

        End Try

        Return ds

    End Function

The markup for the chart follows:

<asp:Chart ID="Chart1" runat="server" Height="336px" Width="348px">
             <Titles>
                 <asp:Title Text="">
                 </asp:Title>
             </Titles>
             <Series>
                 <asp:Series BorderWidth="5" ChartArea="MainChartArea" ChartType="Bar"
                     Color="#000024" Name="MyCategories" YValuesPerPoint="6">
                 </asp:Series>
             </Series>
             <ChartAreas>
                 <asp:ChartArea Name="MainChartArea">
                 </asp:ChartArea>
             </ChartAreas>
         </asp:Chart>
0
Comment
Question by:murbro
2 Comments
 
LVL 25

Accepted Solution

by:
Rouchie earned 500 total points
ID: 39238424
The problem is that ASP.NET has no idea how you want to represent your data.  In fact, the other data columns could well be confusing the rendering engine.  In situations like this its best to create the chart from scratch.  Its not as difficult as it sounds once you get the idea.
Copy my examples in this post but change the chart type to match that which you require:
http://www.codepal.co.uk/show/Create_and_format_an_aspChart_programmatically
0
 

Author Closing Comment

by:murbro
ID: 39249597
Thanks very much
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

932 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now