?
Solved

Graphs in VB

Posted on 2003-02-20
11
Medium Priority
?
756 Views
Last Modified: 2012-05-05
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.
0
Comment
Question by:Sam8932
[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
  • 4
  • 2
  • 2
  • +3
11 Comments
 
LVL 2

Expert Comment

by:Jacamar
ID: 7987358
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.

0
 
LVL 1

Expert Comment

by:HarmnKardn
ID: 7987562
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.
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 7987669
MsChart supports OLEDB connections, how do you access the database?
0
Technology Partners: 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!

 

Author Comment

by:Sam8932
ID: 7989038
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


0
 
LVL 9

Expert Comment

by:apirnia
ID: 7989635
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.
0
 
LVL 18

Accepted Solution

by:
Sethi earned 400 total points
ID: 7992122
If you want to use a free charting tool then MSChart is the only option to you and believe me you can create very smat charting applications with.

There are two code samples that you must see. After these samples you will be able to use MSChart very efficiently:

1. There is a charting sample in Samples folder in the path where VB is installed in your machine.

2. http://www.freevbcode.com/ShowCode.Asp?ID=1538
0
 
LVL 2

Expert Comment

by:Jacamar
ID: 7996442
do you want a hand creating this graph?  I'm available to help.
0
 

Author Comment

by:Sam8932
ID: 8008250
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.  
0
 

Author Comment

by:Sam8932
ID: 8017940
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



0
 
LVL 1

Expert Comment

by:HarmnKardn
ID: 8018014
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").
0
 

Author Comment

by:Sam8932
ID: 8027237
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.  
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

771 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