Solved

ASP.net VB.net Chart

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

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…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

746 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

15 Experts available now in Live!

Get 1:1 Help Now