Solved

Vb.net Graph Control not displaying line graph properly

Posted on 2010-09-16
7
982 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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Suggested Solutions

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

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