Solved

ASP.net VB.net Chart

Posted on 2013-06-10
2
393 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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

685 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