Simple, but functional and VERY effective graph control-VBForums
Page 1 of 2 12 LastLast
Results 1 to 40 of 47

Thread: Simple, but functional and VERY effective graph control

  1. #1

    Thread Starter
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,633

    Simple, but functional and VERY effective graph control

    I have written a small compact graph usercontrol control.

    Features:
    • Squigillians of points
    • Draw Line Graph
    • Draw Bar Graph
    • All Custom Colors
    • Draw Points
    • Draw Axis
    • Fixed Items
    • Save ALL grid and point properties to a file
    • Load a graph from a saved file

    I think that's it.
    With the graph it's possible to do the following:
    • Draw a moving graph, like you see in task manager
    • Draw a histogram, bar and line graphs
    • Draw mathematical equations, like Sin Wave or x^2
    • Draw a moving music graphic equaliser thingy like in media player
    • Create a progress bar

    It's something I knocked up in the last 24hrs. I can't find any bugs, but I am sure one of the little bastards is still lurking around

    Any comments or suggestions would be great.

    Cheers.

    Woka
    Attached Files Attached Files

  2. #2

    Thread Starter
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,633

    Version 2.0

    OK. Here's Version 2.0 of the control.
    It can now handle multiple datasets

    This allows you to add even more functionality...check out the music equalizer demo

    This demo show's you most of the styles and functionality you can do with this control, except the Loading and Saving of the graph.
    I will write a form and add it into the demo to do this.

    Wooooof
    Attached Files Attached Files

  3. #3

    Thread Starter
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,633
    There are a few little bugs left, but they are hard to replicate
    I will clear them up soon.

    One thing it doesn't do, is multiple datasets in bar mode. This is because the last dataset drawn overwrites the previous bars from the other datasets.
    Not sure how to do this yet...maybe offset them or something. Hnmmmmmm

    Woiof

  4. #4
    New Member
    Join Date
    Apr 2005
    Posts
    7

    Re: Simple, but functional and VERY effective graph control

    Wow! Thanks a lot!

    One slight problem, when I try to open your sample programme so I can try and understand how it works, i Get the following errors:
    "Line 13: Class vbGraph.Graph of control Graph1 was not a loaded control class." for each .frm

    I guess this is me being inadequate in using VB, could someone possibly tell me what I need to do? I tried to install VBGraph as a component, but that didn't seem to work.

    Cheers, Chris.

    PS - Here is the VB Code I have for my application, does it seem straightforward to get the information that I am currently writing into the textboxes, to be reperesented in this chart?

    Private Sub Timer1_Timer()
    Dim buffer() As Byte
    'define buffer to use for the data
    'in this configuration you can only send 8 bytes at a time

    ReDim buffer(8)

    'write to PIC
    HIDComm1.WriteTo buffer(), 8

    'read data back from the PIC
    buffer() = HIDComm1.ReadFrom(8)

    'put result from AN0 channel into first text box Its the 8 bits in each of
    'these buffers that I want to Chart in RealTime

    Text1.Text = buffer(1)

    'put result from AN1 channel into second text box
    Text2.Text = buffer(2)

    'put result from AN2 channel into third text box
    Text3.Text = buffer(3)

    'put result from AN4 channel into fourth text box
    Text4.Text = buffer(4)

    'put result from AN5 channel into fifth text box
    Text5.Text = buffer(5)

    'put result from AN6 channel into sixth text box
    Text6.Text = buffer(6)

    'put result from AN7 channel into seventh text box
    Text7.Text = buffer(7)

    End Sub


    Private Sub Form_Load()
    'connect to the USB device as the program starts
    HIDComm1.Connect

    End Sub

    Private Sub Form_Terminate()
    'disconnect from the USB device as prgoram ends
    'THIS IS IMPORTANT
    HIDComm1.Uninit

    End Sub

    Private Sub HIDComm1_ConnectSuccess(ByVal Status As Long)

    Caption = "Huzzah! - Its Connected"

    End Sub

    Private Sub HIDComm1_Disconnected(ByVal Status As Long)

    Caption = "Not Connected"

    End Sub

    Private Sub Timer2_Timer()
    'try and reconnect the PIC
    If HIDComm1.Connected = False Then
    HIDComm1.Connect
    End If

    End Sub

  5. #5
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,716

    Re: Simple, but functional and VERY effective graph control

    Hi Wokawidget,

    I did not look at your usercontrol, but reading about it, I got an idea.
    In this thread http://www.vbforums.com/showthread.php?t=328242 , I did some reserch on fixing the distorted sound, and i got the solution with the trend thing, I tought you can use the same thing to draw graphs...

    Anyways, I wrote some code to see what I mean, put a picturebox on the form, and paste the following code to see it in action.

    The only functions I wrote are: DrawTrend, ExpandPoints, ExpandPointsB, and how to use them in Form_Load.

    Maybe you can incorporate this in your graphing usercontrol...
    VB Code:
    1. Option Explicit
    2.  
    3. Private Type POINT
    4.     X As Double
    5.     Y As Double
    6. End Type
    7.  
    8. Private Sub Form_Load()
    9.     Dim SinglePoints(4) As Double, InTrendPoints() As POINT, OutTrendPoints() As POINT
    10.    
    11.     SinglePoints(0) = 10
    12.     SinglePoints(1) = 35
    13.     SinglePoints(2) = 50
    14.     SinglePoints(3) = 18
    15.     SinglePoints(4) = 13
    16.    
    17.     ' increase the "ExpandTo" param to have even more precision
    18.     InTrendPoints = ExpandPoints(SinglePoints, 60)
    19.     'InTrendPoints = ExpandPointsB(SinglePoints, 60) ' a simpler expand...
    20.     OutTrendPoints = Trend(InTrendPoints, 3)
    21.    
    22.     Picture1.AutoRedraw = True
    23.     DrawTrend Picture1, InTrendPoints, RGB(180, 180, 180)
    24.     DrawTrend Picture1, OutTrendPoints, vbBlue
    25. End Sub
    26.  
    27. Private Sub DrawTrend(Pic As PictureBox, Points() As POINT, ByVal Color As Long, Optional WithPoints As Boolean = False)
    28.     Dim MaxY As Double, MaxX As Double, K As Long, EmptySpaceX As Double, EmptySpaceY As Double
    29.    
    30.     For K = 0 To UBound(Points)
    31.         If Points(K).X > MaxX Then MaxX = Points(K).X
    32.         If Points(K).Y > MaxY Then MaxY = Points(K).Y
    33.     Next K
    34.    
    35.     EmptySpaceX = MaxX * 0.1
    36.     EmptySpaceY = MaxY * 0.1
    37.    
    38.     Pic.Scale (-EmptySpaceX, MaxY + EmptySpaceY)-(MaxX + EmptySpaceX, -EmptySpaceY)
    39.     Picture1.DrawWidth = 1
    40.    
    41.     Pic.Line (-EmptySpaceX, 0)-(MaxX + EmptySpaceX, 0), RGB(128, 128, 128)
    42.     Pic.Line (0, MaxY + EmptySpaceY)-(0, -EmptySpaceY), RGB(128, 128, 128)
    43.    
    44.     Picture1.DrawWidth = 2
    45.     Pic.PSet (Points(0).X, Points(0).Y), Color
    46.    
    47.     If WithPoints Then
    48.         For K = 1 To UBound(Points)
    49.             Pic.PSet (Points(K).X, Points(K).Y), Color
    50.         Next K
    51.     Else
    52.         For K = 1 To UBound(Points)
    53.             Pic.Line -(Points(K).X, Points(K).Y), Color
    54.         Next K
    55.     End If
    56. End Sub
    57.  
    58. Private Function ExpandPointsB(InPoints() As Double, ExpandTo As Long) As POINT()
    59.     Dim OutPoints() As POINT, K As Long, Per As Double, X As Long
    60.    
    61.     If ExpandTo <= 2 Then Exit Function
    62.     ReDim OutPoints(ExpandTo - 1)
    63.    
    64.     For K = 0 To UBound(OutPoints)
    65.         Per = K / CDbl(UBound(OutPoints))
    66.         X = Round(UBound(InPoints) * Per)
    67.        
    68.         OutPoints(K).X = K + 1
    69.         OutPoints(K).Y = InPoints(X)
    70.     Next K
    71.    
    72.     ExpandPointsB = OutPoints
    73. End Function
    74.  
    75. Private Function ExpandPoints(InPoints() As Double, ExpandTo As Long) As POINT()
    76.     Dim OutPoints() As POINT, K As Long, Per As Double, PerX As Double, LngX As Long
    77.    
    78.     If ExpandTo <= 2 Then Exit Function
    79.     ReDim OutPoints(ExpandTo - 1)
    80.    
    81.     For K = 0 To UBound(OutPoints) - 1
    82.         Per = K / CDbl(UBound(OutPoints))
    83.        
    84.         PerX = UBound(InPoints) * Per
    85.         LngX = Fix(PerX)
    86.        
    87.         OutPoints(K).X = K + 1
    88.         OutPoints(K).Y = InPoints(LngX) + (InPoints(LngX + 1) - InPoints(LngX)) * (PerX - LngX)
    89.     Next K
    90.    
    91.     OutPoints(K).X = K + 1
    92.     OutPoints(K).Y = InPoints(UBound(InPoints))
    93.    
    94.     ExpandPoints = OutPoints
    95. End Function
    96.  
    97. Private Function Trend(Data() As POINT, ByVal Degree As Long) As POINT()
    98.     'degree 1 = straight line y=a+bx
    99.     'degree n = polynomials!!
    100.    
    101.     Dim a() As Double
    102.     Dim Ai() As Double
    103.     Dim b() As Double
    104.     Dim P() As Double
    105.     Dim SigmaA() As Double
    106.     Dim SigmaP() As Double
    107.     Dim PointCount As Long
    108.     Dim MaxTerm As Long
    109.     Dim m As Long, n As Long
    110.     Dim i As Long, J As Long
    111.     Dim Ret() As POINT
    112.    
    113.     Degree = Degree + 1
    114.    
    115.     MaxTerm = (2 * (Degree - 1))
    116.     PointCount = UBound(Data) + 1
    117.    
    118.     ReDim SigmaA(MaxTerm - 1)
    119.     ReDim SigmaP(MaxTerm - 1)
    120.    
    121.     ' Get the coefficients lists for matrices A, and P
    122.     For m = 0 To (MaxTerm - 1)
    123.         For n = 0 To (PointCount - 1)
    124.             SigmaA(m) = SigmaA(m) + (Data(n).X ^ (m + 1))
    125.             SigmaP(m) = SigmaP(m) + ((Data(n).X ^ m) * Data(n).Y)
    126.         Next
    127.     Next
    128.    
    129.     ' Create Matrix A, and fill in the coefficients
    130.     ReDim a(Degree - 1, Degree - 1)
    131.     For i = 0 To (Degree - 1)
    132.         For J = 0 To (Degree - 1)
    133.             If i = 0 And J = 0 Then
    134.                 a(i, J) = PointCount
    135.             Else
    136.                a(i, J) = SigmaA((i + J) - 1)
    137.             End If
    138.         Next
    139.     Next
    140.    
    141.     ' Create Matrix P, and fill in the coefficients
    142.     ReDim P(Degree - 1, 0)
    143.     For i = 0 To (Degree - 1)
    144.         P(i, 0) = SigmaP(i)
    145.     Next
    146.    
    147.     ' We have A, and P of AB=P, so we can solve B because B=AiP
    148.     Ai = MxInverse(a)
    149.     b = MxMultiplyCV(Ai, P)
    150.    
    151.     ' Now we solve the equations and generate the list of points
    152.     PointCount = PointCount - 1
    153.     ReDim Ret(PointCount)
    154.    
    155.     ' Work out non exponential first term
    156.     For i = 0 To PointCount
    157.         Ret(i).X = Data(i).X
    158.         Ret(i).Y = b(0, 0)
    159.     Next
    160.    
    161.     ' Work out other exponential terms including exp 1
    162.     For i = 0 To PointCount
    163.         For J = 1 To Degree - 1
    164.             Ret(i).Y = Ret(i).Y + (b(J, 0) * Ret(i).X ^ J)
    165.         Next
    166.     Next
    167.    
    168.     Trend = Ret
    169. End Function
    170.  
    171. Private Function MxMultiplyCV(Matrix1() As Double, ColumnVector() As Double) As Double()
    172.     Dim i As Long
    173.     Dim J As Long
    174.     Dim Rows As Long
    175.     Dim Cols As Long
    176.     Dim Ret() As Double
    177.    
    178.     Rows = UBound(Matrix1, 1)
    179.     Cols = UBound(Matrix1, 2)
    180.    
    181.     ReDim Ret(UBound(ColumnVector, 1), 0) 'returns a column vector
    182.    
    183.     For i = 0 To Rows
    184.         For J = 0 To Cols
    185.             Ret(i, 0) = Ret(i, 0) + (Matrix1(i, J) * ColumnVector(J, 0))
    186.         Next
    187.     Next
    188.    
    189.     MxMultiplyCV = Ret
    190. End Function
    191.  
    192. Private Function MxInverse(Matrix() As Double) As Double()
    193.     Dim i As Long
    194.     Dim J As Long
    195.     Dim Rows As Long
    196.     Dim Cols As Long
    197.     Dim Tmp() As Double
    198.     Dim Ret() As Double
    199.     Dim Degree As Long
    200.    
    201.     Tmp = Matrix
    202.    
    203.     Rows = UBound(Tmp, 1)
    204.     Cols = UBound(Tmp, 2)
    205.     Degree = Cols + 1
    206.    
    207.     'Augment Identity matrix onto matrix M to get [M|I]
    208.     ReDim Preserve Tmp(Rows, (Degree * 2) - 1)
    209.     For i = Degree To (Degree * 2) - 1
    210.         Tmp(i Mod Degree, i) = 1
    211.     Next
    212.    
    213.     ' Now find the inverse using Gauss-Jordan Elimination which should get us [I|A-1]
    214.     MxGaussJordan Tmp
    215.    
    216.     ' Copy the inverse (A-1) part to array to return
    217.     ReDim Ret(Rows, Cols)
    218.     For i = 0 To Rows
    219.         For J = Degree To (Degree * 2) - 1
    220.             Ret(i, J - Degree) = Tmp(i, J)
    221.         Next
    222.     Next
    223.    
    224.     MxInverse = Ret
    225. End Function
    226.  
    227. Private Sub MxGaussJordan(Matrix() As Double)
    228.     Dim Rows As Long
    229.     Dim Cols As Long
    230.     Dim P As Long
    231.     Dim i As Long
    232.     Dim J As Long
    233.     Dim m As Double
    234.     Dim d As Double
    235.     Dim Pivot As Double
    236.    
    237.     Rows = UBound(Matrix, 1)
    238.     Cols = UBound(Matrix, 2)
    239.  
    240.     ' Reduce so we get the leading diagonal
    241.     For P = 0 To Rows
    242.         Pivot = Matrix(P, P)
    243.        
    244.         For i = 0 To Rows
    245.             If Not P = i Then
    246.                 m = Matrix(i, P) / Pivot
    247.                
    248.                 For J = 0 To Cols
    249.                     Matrix(i, J) = Matrix(i, J) + (Matrix(P, J) * -m)
    250.                 Next
    251.             End If
    252.         Next
    253.     Next
    254.    
    255.     'Divide through to get the identity matrix
    256.     'Note: the identity matrix may have very small values (close to zero)
    257.     'because of the way floating points are stored.
    258.     For i = 0 To Rows
    259.         d = Matrix(i, i)
    260.        
    261.         For J = 0 To Cols
    262.             Matrix(i, J) = Matrix(i, J) / d
    263.         Next
    264.     Next
    265. End Sub

  6. #6

    Thread Starter
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,633

    Re: Simple, but functional and VERY effective graph control

    Very nice code indeed!

    Should be quite easy to add in.
    All that should be need, at 1st glance, if a function to take the data from one dataset, and pass it through those functions above, and return another dataset with many many point (so it looks like a curve).

    Woka

  7. #7
    Lively Member
    Join Date
    Feb 2005
    Posts
    115

    Thumbs up Re: Version 2.0

    Quote Originally Posted by Wokawidget
    OK. Here's Version 2.0 of the control.
    It can now handle multiple datasets

    This allows you to add even more functionality...check out the music equalizer demo

    This demo show's you most of the styles and functionality you can do with this control, except the Loading and Saving of the graph.
    I will write a form and add it into the demo to do this.

    Wooooof
    This is one great program! Thanks a lot for sharing it.
    I have couple of questions tho

    1. Is it possible to add Hscroll to line graph, so that if we have about 10000 points to put on the graph we can, lets say see only 100 of them on the picture and then when scrolling see the others. Sort of like real time graph but old point don't disapear they stay there and can be seen if scrolled back.

    2. Zoom in, zoom out Maybe?

    3. A small tutorial on how to do this of course not the whole thing just to have a idea...

    4. Make the graph interactive. show the points, label them when mouse point on one it will show it's coordinates

    5. Just kidding that's a lot to ask already.

    GREAT JOB MAN

  8. #8
    New Member
    Join Date
    May 2006
    Location
    Pakistan
    Posts
    1

    Exclamation Re: Simple, but functional and VERY effective graph control

    Hello Woka )

    Firstly .. its a gr8 program that u have written and it is really helpfull for n00bs like me . But as i am still a n00b , i am having some problems with using vbgraph. I made an ocx from the vb project u posted, and included in my project. Now, all the settings are understandable but i have no clue as to how to pass on the data to be graphed ?? i cud'nt see no variables or arrays or anything of the sort .... and there was nothing on the post . Im using it to make a PC based Oscilloscope ( or atleast planning to use vbgraph for plotting data) coz i cud'nt find any other method to plot data in realtime ......( any suggestions will be greatly appreciated )
    Also, can data values below zero be plotted on the graph ?? If so how ??

    Thanx a lot .... Hope'ing for a speedy response

    << c0d3r >>

  9. #9

    Thread Starter
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,633

    Re: Simple, but functional and VERY effective graph control

    Thanks

    If you open the demo project and look at the code in the forms...frmMusic, frmBars etc.
    You will see the code that adds the data to the graph. It's very simple.

    Woof

    PS, and yes, it does plot -ve values.

  10. #10
    New Member
    Join Date
    Jul 2006
    Posts
    2

    Exclamation Re: Simple, but functional and VERY effective graph control

    I just stumbled on your code and it looks like just what I need. Having read through the thread, I notice you haven't answered a couple of questions which are particularly relevant to me:

    1) "Yeahdisk" writes: "One slight problem, when I try to open your sample programme so I can try and understand how it works, i Get the following errors:
    "Line 13: Class vbGraph.Graph of control Graph1 was not a loaded control class." for each .frm"

    I get this too. How do I overcome it and more importantly, how do I access the control in my own projects?

    2) Rookie7799 writes: "Is it possible to add Hscroll to line graph, so that if we have about 10000 points to put on the graph we can, lets say see only 100 of them on the picture and then when scrolling see the others. Sort of like real time graph but old point don't disapear they stay there and can be seen if scrolled back."

    this is just what I need.

    TIA

    Cheers

  11. #11

  12. #12
    New Member
    Join Date
    Jul 2006
    Posts
    2

    Re: Simple, but functional and VERY effective graph control

    1) the project file. I did also try one with the file extension .vbg - is that the solution file?

    how do I access the control in other projects?

    2) I could give it a crack - any hints on how (I'm still a novice)? I've noticed that you used a picture box as the basis of the graph, but this doesn't include scroll bars in its properties.

    Thanks

  13. #13

  14. #14
    New Member
    Join Date
    Aug 2007
    Posts
    11

    Re: Simple, but functional and VERY effective graph control

    gr8 control!!!

  15. #15
    New Member
    Join Date
    Aug 2007
    Posts
    11

    Re: Simple, but functional and VERY effective graph control

    Hi WokaWidget, It a Gr8 Control, But will be Better if you can post a sample project showing how to show DATA from a Database, on to the GRAPH!!!

    Thanks for this wonderful control, Keep it up.

  16. #16

    Thread Starter
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,633

    Re: Simple, but functional and VERY effective graph control

    Thanks

    Well getting data from a DB and my graph control are 2 completely different things.
    All you need to do is use code similar to what is found here: http://www.vbforums.com/showthread.p...t=vb6+database and then add that to my code demo for the graph, and instead of adding data to the graph from a static function, you call your new function that loads data from a DB.

    Make sense?

    Woka

  17. #17
    New Member
    Join Date
    Aug 2007
    Posts
    11

    Smile Re: Simple, but functional and VERY effective graph control

    Thank You WokaWidget, for the help and all the info!!!

  18. #18
    New Member
    Join Date
    Oct 2007
    Posts
    2

    Re: Simple, but functional and VERY effective graph control

    Hi, I'm having trouble using the graph control.
    I compiled the vbGraph.vbp to an .ocx control object and added it to my project as a component. Now I get an error when I want to use the Dataset type to set up datasets. It says that user-defined type is not defined ??? What should I do differently?

    -e- my bad, I was using the older vbGraph build, which didn't have datasets defined.
    Last edited by navaho; Oct 14th, 2007 at 11:28 PM.

  19. #19

  20. #20
    New Member
    Join Date
    Oct 2007
    Posts
    2

    Re: Simple, but functional and VERY effective graph control

    No errors anymore, I had the wrong vbGraph version, the one which didn't have datasets in it

  21. #21

  22. #22
    New Member
    Join Date
    Nov 2007
    Posts
    2

    Re: Simple, but functional and VERY effective graph control

    Hey Wokawidget, the graph works great. Is there any way to get it to show values along the axes? Or a key for what color line is what?

    Thanks!

  23. #23

    Thread Starter
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,633

    Re: Simple, but functional and VERY effective graph control

    Nope, and nope. Glad you like it.
    This wasn't supposed to replace the MSChart control.
    It was merely to create quick little graphs like in Task Manager and the Media Player equalizer control.

    Woka

  24. #24
    New Member
    Join Date
    Nov 2007
    Posts
    2

    Re: Simple, but functional and VERY effective graph control

    Haha, I didn't even know there was an MSChart control. I'm a java developer by trade but I needed a quick app that could easily make Windows API calls so I gave VB a shot. I'll look into the MSChart control, hope it's as easy to use as your graph control!

  25. #25
    New Member
    Join Date
    Apr 2009
    Posts
    1

    Re: Simple, but functional and VERY effective graph control

    Very nice control and so easy to use.

    Has anyone managed to get the graphs to show the values along the axis yet?

    I've been trying all day with no luck

    If not, could someone lead me in the right direction please?

    Thanks

  26. #26
    New Member
    Join Date
    May 2009
    Posts
    2

    Question Re: Simple, but functional and VERY effective graph control

    Very nice Work Woka !

    One question... how I can save the dataset of a graph ? In a .CSV file for example ?

    Thanks in advanced !

  27. #27

    Thread Starter
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,633

    Re: Simple, but functional and VERY effective graph control

    Thanks

    There is no native way to export the data from the datasets.
    You would have to wraite code that did that for you by looping through the datasets, then looping through the points in the dataset and outputting them to a string, and then write the string to a file.
    the psuedo code would be:
    Code:
    For Each DataSet in DataSets
        Define String csvLine
        For Each point in dataSet.Points
          csvLine += "," + point.value
        Next
        Write csv line string to txt file
    Next
    I dont have the VB6 graph code in front of me I am afraid and it's been a good 4 years since I looked at it

    Woka

  28. #28
    New Member
    Join Date
    May 2009
    Posts
    2

    Re: Simple, but functional and VERY effective graph control

    Dont worry Woka !
    I suppose that the quick way is collect the data before sending them to the graph and save them to an incremental .csv file.

    Something like this

    Code:
    If FlagWriteCSV = True Then
    
    k = CStr(kn) & Chr(9) & CStr(ActSpeed) & Chr(9) & CStr(brakeramp) & Chr(9) & CStr(SpinRamp) & Chr(9) & CStr(ActVMot / 10) & Chr(9) & CStr(ActCurrMot / 10) & Chr(9) & CStr(ActVbus / 10) & Chr(9) & CStr(temperature / 10) & Chr(9) & CStr(Round((PWMrif / 32768) * 100, 0)) & Chr(9) & Date & Chr(9) & Time & Chr(9) & CStr(STATUS.Caption) & Chr(9) & CStr(errorcount) & Chr(9) & CStr(Text1(440).Text) & Chr(9) & CStr(Text1(441).Text) & Chr(9) & CStr(Text1(442).Text) & Chr(9) & CStr(Text1(443).Text)
    
    Print #1, k
    
    kn = kn + 1
    
    Label17.Caption = "Logging:" & " " & k
    
    startlogging.BackColor = vbGreen
    
    Else
    
    stoplogging.BackColor = vbRed
    
    End If

  29. #29
    New Member
    Join Date
    Oct 2009
    Posts
    8

    Re: Simple, but functional and VERY effective graph control

    Dear Wokawidget,

    Thank you for your code! Its just what I am looking for!

    I am trying to use your line graph but I am struggling...

    The data source is a listbox - list2 (There are 47 numeric entries)

    How do I make the graph use these entries?( without scrolling function)

    I have this so far:

    Code:
    1. Private Sub SetupDatasets()
    2.  
    3. Dim objDataset As Dataset
    4. Dim list As Integer
    5.  
    6.  
    7.  
    8.     Set objDataset = Graph1.Datasets.Add
    9.     With objDataset
    10.         .Visible = False
    11.         .ShowPoints = True
    12.         .ShowLines = True
    13.         .ShowBars = False
    14.         .ShowCaps = False
    15.         .LineColor = RGB(0, 0, 255)
    16.         .PointColor = RGB(150, 150, 255)
    17.     End With
    18.      
    19.    
    20.     For i = 0 To List2.ListCount
    21.      list = List2.list(i)
    22.         Next i
    23.  
    24.   list = objDataset
    25.  
    26.    
    27.  
    28. Set objDataset = Graph1.Datasets.Add
    29.  
    30.      With objDataset
    31.          
    32.         .Visible = False
    33.         .ShowPoints = True
    34.         .ShowLines = True
    35.         .ShowBars = False
    36.         .ShowCaps = False
    37.         .LineColor = RGB(0, 0, 255)
    38.         .PointColor = RGB(150, 150, 255)
    39.     End With
    40.  
    41.      
    42.    
    43. End Sub

    I know this is old but it is still good code and it gets the job done!

    Any help would be appreciated!

  30. #30
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    36,798

    Re: Simple, but functional and VERY effective graph control

    Welcome to VBForums

    Based on the example project given (but no testing), I think this is what you want:
    Code:
        For i = 0 To List2.ListCount
          objDataset.Points.Add CInt(List2.list(i))
        Next i

  31. #31
    New Member
    Join Date
    Oct 2009
    Posts
    8

    Re: Simple, but functional and VERY effective graph control

    Hi si_the_geek!!

    Thanks a million!

    This works for me!!

    Now I can tweak it some more!

  32. #32

    Thread Starter
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,633

    Re: Simple, but functional and VERY effective graph control

    Hi,

    Si, thanks for picking this up for me.
    Sorry I didn't get back to you personally, but it seems Si took care of your question

    All points need to be added to the Dataset.Points class, as shown above.
    The graph can handle multiple datasets, and thus plot more than one set of data onto the graph.

    Cheers,

    Woka

  33. #33
    New Member
    Join Date
    Jun 2010
    Posts
    1

    Re: Simple, but functional and VERY effective graph control

    Quote Originally Posted by navaho View Post
    Hi, I'm having trouble using the graph control.
    I compiled the vbGraph.vbp to an .ocx control object and added it to my project as a component. Now I get an error when I want to use the Dataset type to set up datasets. It says that user-defined type is not defined ??? What should I do differently?

    -e- my bad, I was using the older vbGraph build, which didn't have datasets defined.
    ....I had the same problem except could not resolve it. I could only find 2 entries of vbGraph.zip listed here and I made sure to use the most recent. Still getting

    "Can't find project or library"

    and the highlighted line is Dim objDataset As Dataset

  34. #34
    New Member
    Join Date
    Sep 2010
    Location
    Batangas, Philippines
    Posts
    5

    Re: Simple, but functional and VERY effective graph control

    hi! I am new in using vb and i am currently making a project in vb6. my project is suppose to function like this: from a remote sensor, temperature samples will be gathered and transfer the data into computer via SMS. In the computer the interfaced used is VB6, I have been able to save the data into the flex grid, the next thing I should do is to plot it in real time basis.
    -that was a big prob, cause this is my first time in vb and i locked so much of idea about this. please help me here. thanks a lot.

  35. #35

  36. #36
    New Member
    Join Date
    Sep 2010
    Location
    Batangas, Philippines
    Posts
    5

    Question Re: Simple, but functional and VERY effective graph control

    Hi Woka,
    Thanks, finally someone has noticed my post, if you don't mind, where can I find that sample codes? I have downloaded a sample code that you have posted entitled vbgraph, but I can't make it work. when I am trying to run the program, it always has an error : method or data member not found, then the .Redraw has been highlighted. thanks.

    Tin..

  37. #37

  38. #38
    New Member
    Join Date
    Sep 2010
    Location
    Batangas, Philippines
    Posts
    5

    Question Re: Simple, but functional and VERY effective graph control

    hi,
    how could I attached the file? i mean the screen shot for error msg? i am sorry i am really new here and this is my first time to join a forum, what actually am i doing is i run the program, i was thinking if it requires additional api or what? really sorry, im struggling here, thanks for your help


    Additional, Hi, I want to also ask about this equation,

    If lngIndex = 3 Then
    lngValue = 70 + (Rnd * 10) - 5
    ElseIf lngIndex = 2 Then
    lngValue = 50 + (Rnd * 50) - 25
    Else

    I dont understand what's happening here, why should lngValue is changed. Thanks.
    Last edited by cristey; Sep 25th, 2010 at 09:00 AM. Reason: i forgot some important points

  39. #39

    Thread Starter
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,633

    Re: Simple, but functional and VERY effective graph control

    That is my code to get it to produce random graph data using random numbers.
    I probably made it more complex than needed.
    To post a screen shot click on the Go Advanced button at the bottom of this thread while logged in. Then you see a button to attach files.

    Woka

  40. #40
    New Member
    Join Date
    Sep 2010
    Location
    Batangas, Philippines
    Posts
    5

    Thumbs up Re: Simple, but functional and VERY effective graph control

    hi Woka,

    i really like your program, i have download the codes again ad surprised that it worked fine. Thanks so much that would be a big help to my project. thanks a lot ad i hope that you will be able to make more interesting topics.

    Thanks big time!
    Tin. . . .

Page 1 of 2 12 LastLast

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.