Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

ASP.net VB.net Chart

Posted on 2013-06-10
2
Medium Priority
?
417 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:Murray Brown
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 25

Accepted Solution

by:
Rouchie earned 2000 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:Murray Brown
ID: 39249597
Thanks very much
0

Featured Post

Independent Software Vendors: 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

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…
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 is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

730 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