Page 1 of 1

CursorTool and YValues

Posted: Wed Jan 11, 2012 9:16 pm
by 16560757
Hello,

I added a Cursortool (vertical line) for a chart that contains multiple TLineSeries. All series are based on the same XValues (timescale). User can position the Cursortool at a certain X-axis value (which may be between to seriespoints)
I want to read the YValues of all Series at the X-value where the Cursortool is. In case the cursortool is at an X-Value where no Seriespoint exists, then I want to read an interpolated Yvalue.

Is this possible? Until now, I managed to read the XValue of the cursortool position, but I found no way to read the YValues of all series at that point.

Ideas and suggestions are highly appreciated (solutions are, too:-).

Regards, Ronald

Re: CursorTool and YValues

Posted: Thu Jan 12, 2012 10:02 am
by yeray
Hi Ronald,

If I understood well this is exactly what's done in the example at "All features\Welcome !\Chart styles\Standard\Line (Strip)\Interpolating Line series" in the features demo.

Re: CursorTool and YValues

Posted: Thu Jan 12, 2012 1:40 pm
by 16560757
Thanks, that is what I meant!

This raises the next question: I want to draw markers on all series at the given xvalue, regardless if this is a seriespoint or not. Is this possible? If not, would it be possible to mark the XValue with a vertical line overthe whole chart and some kind of label/marker/arrow/text or other means of indication? (like cursortool vertical line does, but cursortool does not have markers)

Thanks, Ronald

Re: CursorTool and YValues

Posted: Thu Jan 12, 2012 3:10 pm
by yeray
Hi Ronald,
rvc wrote:I want to draw markers on all series at the given xvalue, regardless if this is a seriespoint or not. Is this possible?
It's already done in the mentioned demo, isn't it? Concretely at the OnAfterDraw event, the line:

Code: Select all

Chart1.Canvas.Ellipse(xs-4,ys-4,xs+4,ys+4);
Find the example attached:
testInterpolate.zip
(2.38 KiB) Downloaded 316 times

Re: CursorTool and YValues

Posted: Thu Jan 12, 2012 9:35 pm
by 16560757
Hi Yeray,

I was looking for a way to draw lines/marks on Series. Drawing on the canvas leaves me with manualle handling zoom/scroll redrawing etc. the Series.Marks suit my needs, with the only problem being no points for some series at some xvalues.

Regards, Ronald

Re: CursorTool and YValues

Posted: Fri Jan 13, 2012 8:55 am
by yeray
Hi Ronald,

Note the drawing is being done at OnAfterDraw event so the calculations made in it are already considering the *new* chart setting when you zoom/scroll. I can actually zoom/scroll and the interpolation is still drawn correctly in the example attached above.
Well, there is actually one little issue. After zooming, if one segment line is out of the ChartRect, so it's not drawn, the interpolation pointer is still drawn. But this can be avoided adding a simple condition to the drawing process:

Code: Select all

    for i:=0 to Chart1.SeriesCount - 1 do
    begin
      ys := Chart1[i].GetVertAxis.CalcYPosValue(InterpolateLineSeries(Chart1[i],xval));
      if (ys>Chart1.ChartRect.Top) and (ys<Chart1.ChartRect.Bottom) then
      begin
        Chart1.Canvas.Brush.Color := Chart1[i].Color;
        Chart1.Canvas.Ellipse(xs-4,ys-4,xs+4,ys+4);
      end;
    end;
On the other hand, if you also want a mark next to the interpolated points, I'd use Annotation tools or simply drawing the text directly to the canvas, because we already have all the information we need in the OnAfterDraw event.
I've modified the project above to use annotations. I had to force some repaints at OnCursorChange, OnZoom and OnUndoZoom to move the annotations.
testInterpolate.zip
(2.58 KiB) Downloaded 286 times