Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 431
  • Last Modified:

ASP.net VB.net Chart

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
Murray Brown
Asked:
Murray Brown
1 Solution
 
RouchieCommented:
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
 
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor Commented:
Thanks very much
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now