How to create xy scatter chart in vb - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

How to create xy scatter chart in vb

ganesh4uganesh4u Posts: 68Member
I like to create xy scatter type chart(which is available in Excel)in vb.How to do it.

Xy scattter chart means data of 1st row on x axis and data of other rows shows curve corresponding to x axis.See excel curve to understand concept.
Ganesh :)

Comments

  • PavlinIIPavlinII Posts: 404Member
    : I like to create xy scatter type chart(which is available in Excel)in vb.How to do it.
    :
    : Xy scattter chart means data of 1st row on x axis and data of other rows shows curve corresponding to x axis.See excel curve to understand concept.
    : Ganesh :)
    :

    One more question. Do you want you app to control excel and create xy scatter inside excel from it's values OR do you want your app to show the scatter in some picturebox from it's own values?
    The first case should be done like this:
    [code] ActiveWorkbook.Charts.Add
    With ActiveWorkbook.ActiveChart
    .ChartType = xlXYScatterLines
    .SetSourceData Sheets("List1").Range("A1:B3"), xlColumns
    .Location xlLocationAsNewSheet
    .HasTitle = True
    .ChartTitle.Characters.Text = "Name"
    .Axes(xlCategory, xlPrimary).HasTitle = True
    .Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "X values"
    .Axes(xlValue, xlPrimary).HasTitle = True
    .Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "Y values"
    .Axes(xlCategory).HasMajorGridlines = True
    .Axes(xlCategory).HasMinorGridlines = False
    .Axes(xlValue).HasMajorGridlines = True
    .Axes(xlValue).HasMinorGridlines = False
    .HasLegend = False
    End With[/code]I suppose you to have access to the excel ActiveWorkbook (or any other one)..

    The second way: Create picture box Picture 1, choose the color of painted line and draw it pixel by pixel like by this method:
    [code] myColor = RGB(myRed, myGreen, myBlue)
    myColor = SetPixelV(Picture1.hdc, x, y, myColor)[/code]There should be usefull do something like
    RealPictureX = X / Picture1.Width and the same for Y (not to draw beside the canvas)

    Or, if you want just lines, you can use LineTo function
    LineTo Picture1.hDC, x, y

    but in this case, you have to create pen
    hPen = CreatePen(PS_SOLID, 5, RGB(0, 128, 0))
    SelectObject Picture1.hDC, hPen

    (DeleteObject hPen on terminate)
    and to set the first position

    Form1.PSet (FirstX, FirstY), RGB(myRed, myGreen, myBlue)
    SelectObject Picture1.hDC, hPen

    Instead of Picture1.hDC you can use Form1.hDC to paint straight to the form



    [blue][b][italic][size=4]P[/size]avlin [size=4]II[/italic][/size][/b][/blue]

    [purple]Don't take life too seriously anyway you won't escape alive from it![/purple]


  • ganesh4uganesh4u Posts: 68Member
    I want my app to show the scatter in some picturebox from it's own values. or any other control but it should use only vb;i don't want to use excel. Suppose data values as follows.
    A=(10,20,30,38,45)
    B=(5,10,12,18,22)
    C=(3,5,7,10,12)

    I want data in A row should represent X axis values and data in B row should represent Y axis and form a corresponding curve.If possible data in C row should represent Second Y axis and form a corresponding curve.
    i think now my query is clear to you.

    If you can solve this problem please sent me code.


    Ganesh :)

  • PavlinIIPavlinII Posts: 404Member
    : I want my app to show the scatter in some picturebox from it's own values. or any other control but it should use only vb;i don't want to use excel. Suppose data values as follows.
    : A=(10,20,30,38,45)
    : B=(5,10,12,18,22)
    : C=(3,5,7,10,12)
    :
    : I want data in A row should represent X axis values and data in B row should represent Y axis and form a corresponding curve.If possible data in C row should represent Second Y axis and form a corresponding curve.
    : i think now my query is clear to you.
    :
    : If you can solve this problem please sent me code.
    :
    :
    : Ganesh :)
    :
    :
    So, if you want curve scatter, you have a problem because you have to know X and Y of each point.. And calculation regressive functions is complicated. VB do not have any included function for this.
    gdi32.dll does. Take a look to API PolyBezier function to paint Bezier's curve. (You should test the count of input points)
    Input date format is POINTAPI
    Dim Point(0 to 6) As POINTAPI
    Point(0).x = A(0)
    Point(0.y = B(0)
    Point(1).x = A(1)
    Point(1).y = B(1)
    ...
    Point(6).x = A(6)
    Point(6).y = B(6)
    CountOfPoints=7
    PolyBezier Picture1.hDC, Point(0), CountOfPoints

    Number of points is 4+n where n is 3*k, k=1, 2, 3, 4... (I have no idea how to write in english "nasobek" (multiple?).. I hope you understand this..)

    I'm sorry but I don't have time to test this code and tell you more about it.. Try google ;)
    PavlinII
Sign In or Register to comment.