ValueIndex of TcursorTool

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
Calou
Advanced
Posts: 104
Joined: Wed Nov 19, 2008 12:00 am

ValueIndex of TcursorTool

Post by Calou » Tue May 05, 2009 2:03 pm

Hello,

I want to know the value index of a TcursorTool without moving it with the mouse (snap=true)

Is it possible?

Thank you

Regards

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

Post by Yeray » Tue May 05, 2009 2:22 pm

Hi Calou,

Here is how you could do it:

Code: Select all

procedure TForm1.Button1Click(Sender: TObject);
var Index: Integer;
begin
  Index := Series1.Clicked(Chart1.Axes.Bottom.CalcXPosValue(ChartTool1.XValue),
                           Chart1.Axes.Left.CalcYPosValue(ChartTool1.YValue));
  Chart1.Title.Text.Text := IntToStr(Index);
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

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

Post by Yeray » Tue May 05, 2009 2:25 pm

Hi Calou,

I'm not sure to understand you. The index of the tool? But when you want to retrieve it, when it's clicked?
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

Calou
Advanced
Posts: 104
Joined: Wed Nov 19, 2008 12:00 am

Post by Calou » Tue May 05, 2009 2:38 pm

Yes i want the valueindex of the tool to display series values when the chart is shown and before the user move the cursor

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

Post by Yeray » Tue May 05, 2009 3:31 pm

Hi Calou,

I'm afraid that I'm still not sure to understand what exactly you want to do. If you have several tools and you want to know which one is the cursor tool you could do:

Code: Select all

procedure TForm1.FormCreate(Sender: TObject);
var i, CursorIndex: Integer;
begin
  for i:=0 to Chart1.Tools.Count-1 do
  begin
    if (Chart1.Tools[i] is TCursorTool) then
    begin
      CursorIndex := i;
      break;
    end;
  end;

  Chart1.Title.Text.Text := IntToStr(CursorIndex);
end;
Otherwise, if you want to know if your (known) Cursor tool is clicked when the chart is clicked, you could do as follows:

Code: Select all

var MouseX, MouseY: Integer;

procedure TForm1.Chart1MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
  MouseX := X;
  MouseY := Y;
end;

procedure TForm1.Chart1Click(Sender: TObject);
begin
  if (ChartTool1.Clicked(MouseX,MouseY) = TCursorClicked(1)) or
     (ChartTool1.Clicked(MouseX,MouseY) = TCursorClicked(2)) or
     (ChartTool1.Clicked(MouseX,MouseY) = TCursorClicked(3)) then
    Chart1.Title.Text.Text := 'Cursor Tool clicked'
  else
    Chart1.Title.Text.Text := 'Cursor Tool NOT clicked';
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

Calou
Advanced
Posts: 104
Joined: Wed Nov 19, 2008 12:00 am

Post by Calou » Tue May 05, 2009 4:14 pm

that you write in your first answer is good for me. However I have tried your code but index always = -1 because I think i look at ChartTool1.XValue and ChartTool1.YValue before the chart is drawn and their values =0

That i want to do is when the chart is visible i want to print the value of the series where the cursor is. So i try to know the valueindex of the series where the cursor is at the beginning.
I hope it is more clear :oops:

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

Post by Yeray » Wed May 06, 2009 7:40 am

Hi Calou,

If I understand fine, you probably only need to force a chart draw (Chart1.Draw; ). Here is a simple example of what I understood:

Code: Select all

uses series, TeeTools;

procedure TForm1.FormCreate(Sender: TObject);
var i, CursorIndex, SeriesIndex: Integer;
begin
  Chart1.View3D := false;
  CursorIndex := -1;
  SeriesIndex := -1;

  for i:=0 to 3 do
  begin
    Chart1.AddSeries(TPointSeries.Create(self));
    Chart1[i].FillSampleValues(25);
  end;

  Chart1.Tools.Add(TAnnotationTool.Create(self));
  Chart1.Tools.Add(TDragMarksTool.Create(self));
  Chart1.Tools.Add(TAnnotationTool.Create(self));
  Chart1.Tools.Add(TCursorTool.Create(self));

  for i:=0 to Chart1.Tools.Count-1 do
    if (Chart1.Tools[i] is TCursorTool) then
    begin
      CursorIndex := i;
      break;
    end;

  (Chart1.Tools[CursorIndex] as TCursorTool).Series := Chart1[2];
  (Chart1.Tools[CursorIndex] as TCursorTool).Snap := true;

  for i:=0 to Chart1.SeriesCount-1 do
    if (Chart1.Tools[CursorIndex] as TCursorTool).Series = Chart1[i] then
    begin
      SeriesIndex := i;
      break;
    end;

  Chart1.Draw;
  with (Chart1.Tools[CursorIndex] as TCursorTool) do
    Chart1.Title.Text.Text := 'SeriesIndex: ' + IntToStr(SeriesIndex) + '  XValue: ' + FloatToStr(XValue) + '  YValue: ' + FloatToStr(YValue);
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