Solved

Vb.net Graph Control not displaying line graph properly

Posted on 2010-09-16
7
980 Views
Last Modified: 2012-05-10
Hello,
I'm have a weird problem. I've developed a vb.net application with a feature that allows users to create a graph.  Users are able to select one of four graph styles and then generate a graph.  For some reason, I am having a weird result when users select line graph as shown in the image below.  The other selections such a column, stacked, and stacked column are right on the money.
LineGraph.JPG
0
Comment
Question by:chtullu135
  • 4
7 Comments
 

Author Comment

by:chtullu135
ID: 33694199
Here is some additional information.  When I export the graph via the interface, using excel automation, the line graph works fine.  The problem appears to be with the chart object in the form
0
 
LVL 26

Expert Comment

by:Alan Warren
ID: 33750572
Hi chtullu135,

I ran into that myself not long ago, think I initially resolved it by switching the xaxis and yaxis values, line chart draws horizontally, your other chart types draw vertically.

If you give a title to the axisX, you should be able to see if this is the case, because the title will be rendered on the vertical axis for your line chart, but on the horizontal axis for the other chart types, maybe it's the other way round, whatever, you'll see the location of axisX shifts.

<axisx LineColor="64, 64, 64, 64"  LabelAutoFitMaxFontSize="8"  Title="xaxis">

hth

Alan
0
 

Author Comment

by:chtullu135
ID: 33770693
Thanks, I'll give it a try.
0
 

Author Comment

by:chtullu135
ID: 33803207
Hello,

BTW below is the code I am using to create the graph.  It works fine for everything with the exception of a couple of line graphs.  These seem to be the ones that use percentages.
 Dim xfield As String = "ForecastYear"
                    Dim xval As New ArrayList

                    For Each r As DataRow In ds.Rows
                        xval.Add(r.Item(xfield))
                    Next

                    Dim yfield As String = "MetricValue"
                    Dim yval As New ArrayList
                    For Each r As DataRow In ds.Rows
                        If strReportMetricName = "% Renewable Electricity Generation (Including Hydropower), annual" Then
                            yval.Add(r.Item(yfield) * 100)
                        ElseIf strReportMetricName = "% Advanced Vehicles Based on Sales, annual" Then
                            yval.Add(r.Item(yfield) * 100)
                        Else
                            yval.Add(r.Item(yfield))
                        End If

                    Next
                    Chart1.Series(strSeriesName).Points.DataBindXY(xval, yval)

Open in new window

0
 

Accepted Solution

by:
chtullu135 earned 0 total points
ID: 33810251
Actually the array list wasn't the problem.  The array was being populated by a data access function I had written not by the datagridview.  In stepping through the code, I found that the array was being populated in the wrong order.  So the array was receiving out of order data.  I went to the stored procedure that was used to populate this array and found that I had forgotten to add an order by clause to the select statement.  I remembered from basic relational database theory that the sort order of retrieved records is not guaranteed unless you explicitly set it using an Order by clause.  Once I added it, the array was populated correctly.  BTW thanks for the tip about declaring arraylists at the class level.  I'll keep it in mind
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

861 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