Using your Graph Example 9.3 ?

drj

Member
Licensed User
Longtime User
Hi ,

I am using your graph example section 9.3 of the User's guide. I have gotten it to work on plotting several graphs but have run into a problem plotting the following.

I am trying to plot three curves at the same time.

Curve 1. an equation f(x)= x^2 +2 - this plots fine

Curve 2. straight line from (x1,0) to (x1,f(x1)) , this is vertical line that is a low limit

Curve 3. straight line from (x2,0) to (x2,f(x2)) , this is vertical line that is a high limit


in my case x1=2 and x2= 8

Curve 2 and Curve 3 do not work? do you have any ideas on how to achieve this?

Thanks

Jerry
 

klaus

Expert
Licensed User
Longtime User
Sorry, but without seeing your code impossible to help you.
Could you post your project as a zip file (IDE menu Files / Export As Zip) this would be the easiest way for me to help you.
In the mean time you could try to set the Antialiasing filter for your Canvas and see if this solves the problem (User's Guide chapter 9.4).

Best regards.
 
Last edited:
Upvote 0

drj

Member
Licensed User
Longtime User
I fixed this and here is the code - another Q

Hi,

I add this routine to the graphics example. I unscrambled the way the code handles scaling and simplified it. This routine is called to plot a line from x1,y1 to x2, y2 and the line is scaled so it appears within the graph definition. By the way I don't know what but it appears that I had to add 4dpi to the y2 location - I think it compensates for stroke width , not sure.

The existing graph code is designed to plot multiple curves each with the same number of points via the curve array.

This code will allow you to lay lines anywhere on the graph.

I am plotting a curve and this showing two lines intersecting the curve.

Another Q - I wanted to plot an x or 0 or designation at the location in which the curves intersect. I tried using DrawPoint but it did not do anything. Any ideas?

Jerry


Sub PlotLine(x1location As Double, y1location As Double,x2location As Double, y2location As Double, i As Int)

Dim x1, y1, x2, y2 As Float


If x1location < ScaleXMin Then x1location=ScaleXMin
If x2location < ScaleXMin Then x2location=ScaleXMin

If x1location > ScaleXMax Then x1location=ScaleXMax
If x2location > ScaleXMax Then x2location=ScaleXMax

If y1location < ScaleYMin Then y1location=ScaleYMin
If y2location < ScaleYMin Then y2location=ScaleYMin

If y1location > ScaleYMax Then y1location=ScaleYMax
If y2location > ScaleYMax Then y2location=ScaleYMax


x1= GridX0+(Abs(ScaleXMin)+ x1location)*GridDeltaX


y1 = GridY0 + (ScaleYMax - y1location) * ScaleY

x2= GridX0+(Abs(ScaleXMin)+ x2location)*GridDeltaX


y2 = GridY0 + (ScaleYMax - y2location) * ScaleY + 4dip



cvsGraph.DrawLine(x1, y1, x2, y2, CurveLineColor(i), CurveLineStroke(i))

' ???????? cvsGraph.DrawPoint(x2, y2, Colors.black)


End Sub
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
Couldn't you post your project as a zip file as already requested ?
The code you show should work, but without testing it myself it's impossible to help.
Why do you use Abs(ScaleXMin) and not ScaleXMin ?
To draw some text you must use DrawText similar to the drawing of the sclae values.

Best regards.
 
Upvote 0

drj

Member
Licensed User
Longtime User
Hi Thanks for getting back to me

Hi,

I can't post my project, it has over 30 activities and a large class module. Each Activity has a database , layout and may or may not have graphics.

I am only working on specifics of plotting. The code I sent is working.

I used ABS(ScaleXMin) because in the equation I use and have show I need to could the number of absolute units from the left side of the graph origin. For example , is xmin = -10 and I want x = 3 then we want to know how far to display x from the origin and that is 13 units over.

I have done the same for text.
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
As I already said, your code should work.
Could you make a small project showing the problem ?

Concerning the use of the Abs value.
Instead of
B4X:
x1= GridX0 + (Abs(ScaleXMin) + x1location) * GridDeltaX
You should use
B4X:
x1 = GridX0 + (x1location - ScaleXMin) * GridDeltaX
In your case if ScaleXMin > 0 you'll be wrong.
With your example
ScaleXMin = -3 and X = 10
Abs(-3) + 10 = 13, that's OK
but with
ScaleXMin = 3 and X = 10
Abs(3) + 10 = 13, which is wrong you would expect 7 !
With my equation you have
10 - (-3) = 13, OK
10 - 3 = 7, OK

Best regards.
 
Upvote 0

drj

Member
Licensed User
Longtime User
Hi , thanks I see I made an error

Hi,

I got it working and created a small project for you. It works now.

How do I email it to you, through normal email?


I will email a pic of what the screen looks like too.

I created a working small project - I tool graph and modified it

I changed it so you can specify the ranges of x to show , to automatically compute the yscaling from data and how to draw straight lines on the graph with text

tell me how to email it to you ,

Thanks for your help

Jerry
 
Upvote 0

drj

Member
Licensed User
Longtime User
Hi here is a working example of graph

Hi,

I got it working , see attached.

You can change x scale and y scale changes with data and you can plot lines and curves.

Thanks for your help.

Jerry
 

Attachments

  • TestGraphExample.zip
    224.6 KB · Views: 215
Upvote 0
Top