Results 1 to 11 of 11

Thread: newbee...ploting a graph

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Dec 2005
    Posts
    83

    newbee...ploting a graph

    hey guys i'm not good at all at vb have only been doing it a month and not for much of that month, thing is i've to submit a maths project to include a vb app as part of it.
    basically i have a programm that will write the solution to an equation over a interval to at txt file. that i can do. it looks stg like this in the txt file
    (the vb app uses a loop to generate the y vaulues for each x)

    x1 y1
    x2 y2
    x3 y3
    x4 y4

    etc

    what i then do is open an excel doc and plot the x's vs y's to get a nice graph!!!
    what i want to do is to have the vb app create its own graph and plot the points itself.. i've a feeling this is possible because i saw in the "ole" box you can choose to create a graph. but thats as much as i know.

    any help or guidance would be much apprecieated!!!
    thanks....james

  2. #2
    Frenzied Member
    Join Date
    May 2003
    Location
    Sydney
    Posts
    1,123

    Re: newbee...ploting a graph

    so u want to create a graph in excel using the data in your text file?

    PS welcome to the forums...

    let me try some code myself first....

  3. #3
    Frenzied Member Andrew G's Avatar
    Join Date
    Nov 2005
    Location
    Sydney
    Posts
    1,587

    Re: newbee...ploting a graph

    Welcome to the forums

    This is to add the chart to your own program, not excel.
    To put a graph similar to Excels (actually exactly like excel's) you'll need the microsoft chart control. To load it goto components (in the project menu) and scroll down to it and select it. You then use columncount and rowcount to set how many columns and rows you need, then move through them useing column and row properties and add your values in the data property.

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Dec 2005
    Posts
    83

    Re: newbee...ploting a graph

    thanks guy
    i got that ms chart thing up but i'm not sure if its what i'm looking for
    i need an x y scatter chart
    all my programme is is basically a loop

    it loops x values from say -3 to +3
    then it returns a y vaule for a particular x
    then it loops back and but in a new value for x
    then out comes a new value for y

    as it goes through each loop it writes the x and y values to a txt file
    which i can then import to excel and plot the graph

    what i need is not to use excel at all..
    please.. speak to me like i;m retarded!!!

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Dec 2005
    Posts
    83

    Re: newbee...ploting a graph

    ohh
    just found an x y scatter chart
    how to i tell it my x and y values???? i think thats my problem

  6. #6
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: newbee...ploting a graph


  7. #7
    Old Member moeur's Avatar
    Join Date
    Nov 2004
    Location
    Wait'n for Free Stuff
    Posts
    2,712

    Re: newbee...ploting a graph

    The easiest way to plat data is to put it into a 2-d array where
    arrData(i,1) = Xi
    arrData(i,2) = Yi
    then use the ChartData Property of the MSChart control.
    VB Code:
    1. MSChart1.ChartData = arrPrices
    For your purposes set the Chart type to VtChChartType2dXY
    Here is an example
    VB Code:
    1. Dim arrPrices()
    2. Dim i As Integer
    3. Dim maxval As Integer
    4.  
    5. MSChart1.chartType = VtChChartType2dXY
    6.  
    7. maxval = 100
    8. ReDim arrPrices(1 To maxval, 1 To 2)
    9. For i = 1 To maxval
    10.    'X-value
    11.    arrPrices(i, 1) = Sin(i / 5) * 50
    12.    'y-Value
    13.    arrPrices(i, 2) = Sin(i / 10) * 50
    14. Next i
    15. MSChart1.ChartData = arrPrices

    If you set ChartType to VtChChartType2dLine, then you don't need X-values. A 1-d array in this case will plot Y-values vs. x=1,2,3,4,... A 2-d Array will plot two data sets.

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Dec 2005
    Posts
    83

    Re: newbee...ploting a graph

    hey moeur
    thanks a mil
    havnt got it to work for my particular app yet but at least i can get the graph to plot from your code so i have a solid starting point all i need to do now is adapt, i never knew about "arrays" before (as my name suggests i am a fish!) but i figure once i brush up on them i should get some kind of result.
    if i succeed i'll post again (give me a few days!!!!)
    james

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Dec 2005
    Posts
    83

    Re: newbee...ploting a graph

    woo hoo woo hoo
    i got it to work
    thanks a million you guys!!!
    now i can concentrate on thermodynamics (exams post christmas)

    just one thing if anyone could help me
    when i start the app the graph is there but theres already 4 crazy plots on it
    when i run the app they dissappear and my plot comes up
    how can i get the graph to be blank as soon as i open the project???
    dont worry if you dont know, its functional now anyways!!!

    thanks again
    james

  10. #10
    Fanatic Member lerroux's Avatar
    Join Date
    Nov 2005
    Location
    Welcome to the darkside... we have cookies
    Posts
    646

    Re: newbee...ploting a graph

    how can i get the graph to be blank as soon as i open the project???
    dont worry if you dont know, its functional now anyways!!!
    try setting the chart value = nothing or "" on formload....

  11. #11
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: newbee...ploting a graph

    Go to properties of the graph, and delete the values that draw the default chart.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width