
I need to draw some lines on the chart.
I have a chart that shows point data
I want to draw a line from specific data value (these are not in the data set used to create the points on the chart), lets say I have X axis from 0 to 100 and Y axes from 0 to 50
I want to draw a line from data values 10,30 to 30,45
How do I calculate the X and Y position on the chart so that I can use the something like
lnX1 = lnXPoint1
lnY1 = lnYPoint1
lnX2 =lnXPoint2
lnY2 = lnYPoint1
loGfx.DrawLine(.Pens.Green, lnX1, lnY1, lnX2, lnY2)
in the afterchart to draw the lines



David,
A solution would be:
You have to determine the relation between your fixed line points and the graph if you can calculate this I believe the easiest way is to add an other value to your dataset with these calculated (default) data and have a 2nd line drawn accordingly
in any colour you desire.
Regards,
Koen



Hi Koen,
I tried that as I have the data values for the 1st and last points.
I added these to the data set and nulls for the values in between but because of the nulls the line from 1st to last point is not drawn by the line graph.
Hence I need to be able to calculate the real graph x and y values so I can draw the line manually in code in the afterdraw event
David



david,
not very clear to me, why nulls? try it with insert the value you would like to have the line te be drawn.
Koen



Koen,
I only know the start and end values for the line.
I have say 20 data points.
If I calaculate the value for the line points for each of the data point entries then I get a jagged line rather than a perfectly straight one due to rounding etc I think.
I also need to draw a vertical line on the graph on the X axis at a value that I know, but which does not exist in the data set. That I don't think I can do with data entries since it only exists as the last X value and has a zero Y value and a higher
Y value.
I need to find out how Foxcharts determins the position of a data point X Y when it draws it. With that I can use my dat values for the start and end points of the line and just draw them, perfectly straight
David



David,
To know how FoxCharts is determinating the points where and how to draw the best is to open your debugger and follow stepbystep the coding , it is not so magical afterall all the methods are logicaly named.
Please report back if you encounter more difficulties after you have figured that what you are looking for.
Regards,
Koen



Hi Koen,
Yes I'll do that.
I posted here 1st just in case someone hd already done that and so would save a lot of time
David



OK this seems to work
Subclassed FoxCharts and in th subclass added
Method  set_x_y_4_value
Propery _x_coordinate
Property _Y_coordinate
In the Afterchart have this code
this.set_x_y_4_value(0,66)
lnX1 = this._x_coordinate
lnY1 = this._y_coordinate
this.set_x_y_4_value(32,57)
lnX2 = this._x_coordinate
lnY2 = this._y_coordinate
LOCAL loGfx as xfcGraphics
loGfx = This.oGfx
WITH _SCREEN.SYSTEM.Drawing
loGfx.DrawLine(.Pens.Green, lnX1, lny1, lnX2, lny2)
ENDWITH
********************************
Code for method set_x_y_4_value
LPARAMETERS tnXValue, tnYValue
LOCAL ln3D, lnAdjust, lnBetween, lnChartsCount, lnHeight, ;
lnLeftMargin, lnMaxValue, lnPointHeight, lnRecs, lnValue, ;
lnWidth, lnYBase, lnx1, lny1
** lnXValue = Param_Val(tnXValue,0)
** lnYValue = Param_Val(tnYValue,0)
lnXValue = tnXValue
lnYValue = tnYValue
lnLeftMargin = THIS._YAxisWidth + THIS._LeftOffset
lnChartsCount = THIS.ChartsCount
ln3D = THIS._3D
lnMaxValue = THIS._ScaleRange
lnRecs = THIS._nRecords
lnWidth = THIS.ChartCanvas.WIDTH  THIS._YAxisWidth  THIS._LeftOffset  (ln3D * lnChartsCount)  THIS._RightOffset
lnAdjust = ln3D * lnChartsCount
lnHeight = This.ChartCanvas.Height  This._XAxisHeight  This._TopOffSet  (ln3D * lnChartsCount)
lnYBase = This._TopOffSet + lnHeight  lnAdjust + (ln3D * lnChartsCount)
IF THIS.Multichart AND THIS.MultiChartMargin
lnBetween = lnWidth / (lnRecs)
ELSE
lnBetween = lnWidth / (lnRecs  IIF(lnRecs = 1, 0, 1))
ENDIF
lnx1 = lnLeftMargin + (lnBetween * lnXvalue) + lnAdjust + IIF(This.Multichart AND This.MultichartMargin , (lnBetween / 2), 0)
lnYValue = lnYValue + THIS._ScaleAdjust
lnPointHeight = lnYValue / lnMaxValue * m.lnHeight
lny1 = lnYBase  lnPointHeight
THIS._x_coordinate = lnx1
THIS._y_coordinate = lny1

