Results 1 to 4 of 4

Thread: Making A 2D Line Graph From An Array - Brand New at this

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2013
    Posts
    1

    Making A 2D Line Graph From An Array - Brand New at this

    Hi, I'm brand spanking-new to computers basically and have no idea what I'm doing.

    I'm doing a math project where I ran a loop to count the prime numbers and then divide the number of primes by whatever number I'm at to get the current percentage of primes. I have the two values set to come out as Array1 and Array2 (p and j in my loop).

    Now I want to create a graphical representation of this data set with a 2d line graph but the graph tool is really confusing.

    I managed to do all of this:

    Dim Array1() As Long
    Dim Array2() As Decimal

    For p = 1 To UpperBound

    l = p / 2
    IsPrime = True
    For i = 1 To Math.Sqrt(l)
    If p Mod 2 = 0 Or p = 1 Or p Mod ((2 * i) + 1) = 0 Then
    IsPrime = False
    Exit For
    End If
    Next

    If IsPrime = True Or p = 2 Then
    k += 1
    Else
    k = k
    End If

    If p = 1 Then
    j = 0
    Else
    j = k / p
    End If

    ReDim Preserve Array1(p)
    Array1(p) = p
    ReDim Preserve Array2(p)
    Array2(p) = j



    I took out all the Dim parts for space, but I have no idea how to turn this into a graph. Any help would be massively appreciated, thanks.

  2. #2
    Hyperactive Member
    Join Date
    Jan 2010
    Posts
    259

    Re: Making A 2D Line Graph From An Array - Brand New at this

    I'm not up and up on all the graphing technologies, but there are several methods.

    A) You can make your own. Not recommend for you obviously unless you want to try making controls.
    B) Use the built in chart control. Documentation here
    C) Use a third-party control. You would have to refer to their documentation on how to use it.

    That being said, have you tried anything at all for graphing or did you just not know where to start?

  3. #3
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: Making A 2D Line Graph From An Array - Brand New at this

    Well first your prime test includes 1 which isn't a prime and excludes 2 and 3 which are. But what exactly are you graphing? Your arrays have only one significant value no matter how large they are. It's not at all clear why you need an array at all, in fact. Your stated aim of graphing % of numbers that are prime by number reached makes very little sense not least because values will swing wildly.

    1 > 0
    2 > 50
    3 > 66
    4 > 50
    5 > 60
    6 > 50
    7 > 57
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  4. #4
    PowerPoster SJWhiteley's Avatar
    Join Date
    Feb 2009
    Location
    South of the Mason-Dixon Line
    Posts
    2,256

    Re: Making A 2D Line Graph From An Array - Brand New at this

    1. Create an array of drawing.pointF() structures;
    2. Parse your coordinate arrays into the .X and .Y properties of the PointF structures;
    2a. Scale the X and Y values for the pixel region you want to plot the points in (note that the origin is top left instead of bottom left);
    3. Override the OnPaint() method or handle the Paint() event;
    4. Draw the PointF array structure using graphics.DrawLines();
    5. In the resize event, rescale the PointF array as appropriate, and Invalidate the drawing region.
    "Ok, my response to that is pending a Google search" - Bucky Katt.
    "There are two types of people in the world: Those who can extrapolate from incomplete data sets." - Unk.
    "Before you can 'think outside the box' you need to understand where the box is."

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