TDBChart OnClickSeries gives wrong ValueIndex

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
wvisser
Newbie
Newbie
Posts: 5
Joined: Fri Sep 09, 2016 12:00 am
Contact:

TDBChart OnClickSeries gives wrong ValueIndex

Post by wvisser » Wed Mar 29, 2017 5:31 pm

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

Yeray
Site Admin
Site Admin
Posts: 9612
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: TDBChart OnClickSeries gives wrong ValueIndex

Post by Yeray » Thu Mar 30, 2017 10:25 am

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.
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

wvisser
Newbie
Newbie
Posts: 5
Joined: Fri Sep 09, 2016 12:00 am
Contact:

Re: TDBChart OnClickSeries gives wrong ValueIndex

Post by wvisser » Mon Apr 03, 2017 7:24 am

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

Yeray
Site Admin
Site Admin
Posts: 9612
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: TDBChart OnClickSeries gives wrong ValueIndex

Post by Yeray » Tue Apr 04, 2017 8:11 am

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;
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Post Reply