Link to home
Start Free TrialLog in
Avatar of Sam8932
Sam8932

asked on

Graphs in VB

I'm trying to incorporate graphs into my VB application.  The data in the graphs will be coming from a database. I have never done this before.  What is the best way to do this?  I've been messing around with MSCharts but really not getting anywhere.  Thanks.
Avatar of Jacamar
Jacamar

I like to use a picturebox.  You can set the scale and then have your points that you want print out.  They can look very nice if done correctly.

Picture1.scale (0,10)-(10,0)
' First data set is top left corner, second is bottom right

after this, you can draw lines from point to point using
picture1.line (X,Y)-(X2,Y2)
data sets are the two points.

Other than that, you just have to play around with loops and variables till you get what you want.

MSCharts has a somewhat awkward interface, and the "automatic scaling" feature can really make your chart ugly.  However it is a quick and easy solution.

There are some good examples of using picture boxes and MSChart at
http://www.engineering.usu.edu/cee/faculty/gurro/Software_Calculators/VisualBasic_Docs/VisualBasic6_Gottfried_Summaries_Examples.htm
Scroll down to "Examples using graphic commands"

There are plenty of commercial charting components that work nicely too.  They are somewhat expensive.
Avatar of Richie_Simonetti
MsChart supports OLEDB connections, how do you access the database?
Avatar of Sam8932

ASKER

Richie,
I've been trying to put the data into a 2 dem. array, but like I said, I haven't been having too much luck.  

I've never used picture boxes before so I'll have to mess with them.  This is my first "real" VB project so I'm still green.  I wish I could show you the graph I'm trying to make.  I think it would be helpfull, but I'm unable to paste it here.  I'll keep you posted on how things are going.

Thanks


There is a tool Called Chart FX. This is one of the best ones I have ever seen. You can download a free trial from their Web page http://www.softwarefx.com/
Very easy to use and very power full. You can even feed it Live XML data.
I use this in my ASP pages. In my ASP I conect to my Database run a query, get the data in to a recordset and Chart FX will graph the record set for you.
ASKER CERTIFIED SOLUTION
Avatar of Sethi
Sethi
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
do you want a hand creating this graph?  I'm available to help.
Avatar of Sam8932

ASKER

Thank you everyone.  All of your help is very much appreciated.  I will try everyone's suggestions to see which one fits my needs the best.  Jacamar, I will work on this for a week or so and see if I can figure it out on my own.  I find I learn more that way.  I hope to have this figured out by the end of next week.  My department is very busy this time of year and I'm sometimes pulled off of my projects to help in other areas. I may end up taking you up on your offer to help though. Again, thank you all very much.  
Avatar of Sam8932

ASKER

Hello everyone.  I have a question about MSCharts.  I'll try to explain this the best I can.  I'm looking at one of the examples that Sethi has listed.  With this example the MSChart's DataSource is set to the recordset.  
Example:
adoCost.Open "SELECT * FROM Cost", adoConn,     adOpenStatic, adLockOptimistic

With MSChart1
     Set .DataSource = adoCost
        .ShowLegend = True
        .Plot.DataSeriesInRow = False
        .Plot.Wall.Brush.Style = VtBrushStyleSolid
End With


The question I have is this - does the data have to be in a table a certain way to use the MSChart? For example, the db the example is using looks like this (TABLE 1).  

statename col1 col2 col3 col4 etc..
R1        10   18   22   28   etc..
R2        12   21   25   30   etc..

The MSChart works fine with this data.  When I get the data by joining two tables the data appears in the table like this (TABLE 2 - this isn't actually a table.  Just the way the data appears using the JOIN statement).

R1  R2
10  12
18  21
22  25
28  30

Using this as my datasource, I get a blank MSChart.  It doesn't work.  If I have to do it the first way I have to first create TABLE 1 and then add the data to that table from the JOIN statement that created TABLE 2. If I have to do this I can, but it would be much easier and more efficient if I could grab the data from the existing tables with the JOIN statement(giving me TABLE 2) and setting the MSChart's datasource to that. I hope this is understandable. It's kind of difficult to explain.

Thanks



I'd say write a function that creates a new two dimensional array, and fills this new array.  Iterate through the new array the opposite way you iterate through the database-provided array, and you'll have successfully transformed the data.  Remember, Ubound and Lbound's second argument is the dimension of the array you're interested in.

Also remember that you can explicitly set the column you want to order by in the SQL statement (using "ORDER BY columnName").
Avatar of Sam8932

ASKER

I'm using MSCharts and it seems to be working fine.  I figured out the answer to my last question.  Once I set .Plot.DataSeriesInRow = False the MSChart worked fine with my JOIN query.  I have 4 graphs finished with 4 or 5 left to do.  I'm hoping to complete them without any problems. I awarded the points to Sethi.  I found his examples the most helpful.  HarmnKardn, If you feel this is unfair, let me know, I would have no problem awarding you points as well. Thanks to everyone once again.