Page 1 of 1

TDBChart OnClickSeries gives wrong ValueIndex

Posted: Wed Mar 29, 2017 5:31 pm
by 16579113
Hello,

I use the OnClickSeries event to get the X value in a TLineSeries chart from the ValueIndex using Series.XValues[ValueIndex].
However, it looks like most of the time the Index returned in the OnClickSeries evenat after clicking is corresponding to the previous point in the series.
The X parameter and axis are of TDatetime time, so the X value is in the order of 42400 or something (around year 2016). Between 2 points there often is a day or so. Is this a round off error? Is the resolution to do this not sufficient to keep 2 points of say 42400 and 42401 apart with OnClickSeries?

Also if I determine the index using Series.Clicked(X,Y) I get the index of the prior point.

Or am I overlooking something.

Thanks, Wilfried

Re: TDBChart OnClickSeries gives wrong ValueIndex

Posted: Thu Mar 30, 2017 10:25 am
by yeray
Hello Wilfried,

Note the points are the edges of each line segment, not the lines themselves. So, the click function has to return one edge point or the other, and it returns the first one.

Re: TDBChart OnClickSeries gives wrong ValueIndex

Posted: Mon Apr 03, 2017 7:24 am
by 16579113
Thanks, so actually, the clickseries event is triggered by clicking the line segment?
What would then be the best approach to get the index of the pointer if the pointers between the line segments are clicked? Just add 1 to the index?

regards, Wilfried

Re: TDBChart OnClickSeries gives wrong ValueIndex

Posted: Tue Apr 04, 2017 8:11 am
by yeray
Hello,

OnClickSeries event is triggered by clicking on the pointer and the line segment. You can differentiate one or the other with some code:

Code: Select all

type TSeriesAccess=class(TChartSeries);

procedure TForm1.Chart1ClickSeries(Sender: TCustomChart; Series: TChartSeries;
  ValueIndex: Integer; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  if TSeriesAccess(Series).ClickedPointer(ValueIndex,
       Series.GetHorizAxis.CalcXPosValue(Series.XValue[ValueIndex]),
       Series.GetVertAxis.CalcYPosValue(Series.YValue[ValueIndex]),
       X, Y) then
     Caption:='Pointer Clicked: ' + IntToStr(ValueIndex)
  else
     Caption:='Line segment Clicked: ' + IntToStr(ValueIndex) + ' - ' + IntToStr(ValueIndex+1);
end;