Initial position of TCursorTool

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
PoLabs
Newbie
Newbie
Posts: 28
Joined: Wed Jun 06, 2007 12:00 am

Initial position of TCursorTool

Post by PoLabs » Wed Jul 15, 2009 7:34 am

Hi,

I have a 2D chart with 2 vertical cursors which are by default positioned in center of my graph. How can I move them to initil position that differe from center.

eg. I would like to position cursor 1 to the left on chart and cursor 2 to the right. I saw you could set XValue or YValue bur what if my series had more than one same YValue or XValue?

Thank you in advance.

Best regards.

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

Re: Initial position of TCursorTool

Post by Yeray » Wed Jul 15, 2009 8:28 am

Hi PoLabs,

Please, take a look at the following example. Everything seems to work as expected:

Code: Select all

uses series, TeeTools;

procedure TForm1.FormCreate(Sender: TObject);
var series1: TPointSeries;
    i: Integer;
    cursor1, cursor2: TCursorTool;
begin
  Chart1.View3D := false;

  series1 := TPointSeries.Create(self);
  Chart1.AddSeries(series1);

  for i:=0 to 25 do
    series1.AddXY(i, round(random*10));

  for i:=0 to 25 do
    series1.AddXY(i, round(random*10));

  cursor1 := TCursorTool.Create(self);
  cursor2 := TCursorTool.Create(self);

  Chart1.Tools.Add(cursor1);
  Chart1.Tools.Add(cursor2);

  cursor1.Style := cssVertical;
  cursor2.Style := cssVertical;

  cursor1.Pen.Color := clRed;
  cursor2.Pen.Color := clGreen;

  Chart1.Draw;
  cursor1.XValue := series1.XValues.MinValue;
  cursor2.XValue := series1.XValues.MaxValue;
end;
If there is any important step I missed, please post here a code (or attach a simple example project) we can run as-is to reproduce the problem here.
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

PoLabs
Newbie
Newbie
Posts: 28
Joined: Wed Jun 06, 2007 12:00 am

Re: Initial position of TCursorTool

Post by PoLabs » Wed Jul 15, 2009 8:41 am

Dummy me!! I am so deep into it so I just need to step on step back to see the solution. :oops:

Thank you very much.

Best regards.

PoLabs
Newbie
Newbie
Posts: 28
Joined: Wed Jun 06, 2007 12:00 am

Re: Initial position of TCursorTool

Post by PoLabs » Wed Jul 15, 2009 9:50 am

One more question. :oops:

What if TCursorTool doesn't have assigned series property? Is still possible to set position of cursor?

I am using one cursor (general on chart) for several series, so I never really need one series to be assigned to cursor and I still would like to set it's position. Is that possible? I assume tha position could be only set if series is assigned to TCursorTool.

Thanks.
BR

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

Re: Initial position of TCursorTool

Post by Yeray » Wed Jul 15, 2009 12:05 pm

Hi BR,

In the example I posted above I used two cursor tools without linking them to any series. I only used a series to obtain the left and the right values. You can also use the axis if you want:

Code: Select all

  cursor1.XValue := Chart1.Axes.Bottom.Minimum;
  cursor2.XValue := Chart1.Axes.Bottom.Maximum;
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

PoLabs
Newbie
Newbie
Posts: 28
Joined: Wed Jun 06, 2007 12:00 am

Re: Initial position of TCursorTool

Post by PoLabs » Wed Jul 15, 2009 12:12 pm

Thank you very much. It works! :)

Best regards,
Aljosa

PoLabs
Newbie
Newbie
Posts: 28
Joined: Wed Jun 06, 2007 12:00 am

Re: Initial position of TCursorTool

Post by PoLabs » Wed Jul 15, 2009 1:06 pm

Again me... :oops:

I have some TLabel objects which I would like to move along with cursors. It is not problem to do that while moving cursor (i use onchange event), but how can I do that programaticly to set labels at cursor position?

an eg.
Label1.Left := GetCoordsFromvalue(Cursor.XValue)

What should be that GetCoordsFromvalue function?

Thanks.

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

Re: Initial position of TCursorTool

Post by Yeray » Wed Jul 15, 2009 2:41 pm

Hi BR,

This is the one:

Code: Select all

tChart1.Axes.Bottom.CalcXPosValue();
PoLabs wrote:Again me... :oops:
Don't worry. We are here for that!
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

PoLabs
Newbie
Newbie
Posts: 28
Joined: Wed Jun 06, 2007 12:00 am

Re: Initial position of TCursorTool

Post by PoLabs » Wed Jul 15, 2009 7:15 pm

Hi,

thanks for your answer. Your support is realy good.

When I try to use Chart.Axes.Bottom.CalcPos... but on runtime I get for every point 0. My axis min is -5 and max is +5. I set cursor C1 to left (-5) and C2 to right (5) and that works fine. When I try to move coresponding label (labels marks cursor like an eg. 'C1', 'C2') I would need coords to set properties Left and Top. I tried it with Label1.Left := Chart.Axes.Bottom.CalcPosFromValue(Chart.Axes.Bottom.Minimum), but if I inspect that property I alwys get 0 on runtime.
Well if there exist any answer to that I would very happy in other case I will just ignore it and remove labels and forget about it. Don't want to loose time on pretty small thing.

Thank you again.
Aljosa

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

Re: Initial position of TCursorTool

Post by Yeray » Thu Jul 16, 2009 10:48 am

Hi

If I understand well you simply need to assign the new label X position at OnChartToolChange event. Here is a complete example using annotation tool instead of labels:

Code: Select all

uses series;

var cursor1, cursor2: TCursorTool;
    annot1, annot2: TAnnotationTool;

procedure TForm1.FormCreate(Sender: TObject);
var series1: TPointSeries;
    i: Integer;
begin
  Chart1.View3D := false;

  series1 := TPointSeries.Create(self);
  Chart1.AddSeries(series1);

  for i:=0 to 25 do
    series1.AddXY(i, round(random*10));

  for i:=0 to 25 do
    series1.AddXY(i, round(random*10));

  cursor1 := TCursorTool.Create(self);
  cursor2 := TCursorTool.Create(self);
  Chart1.Tools.Add(cursor1);
  Chart1.Tools.Add(cursor2);
  cursor1.Style := cssVertical;
  cursor2.Style := cssVertical;
  cursor1.Pen.Color := clRed;
  cursor2.Pen.Color := clGreen;

  annot1 := TAnnotationTool.Create(self);
  annot2 := TAnnotationTool.Create(self);
  Chart1.Tools.Add(annot1);
  Chart1.Tools.Add(annot2);
  annot1.Text := 'Q1';
  annot2.Text := 'Q2';
  annot1.Shape.Color := cursor1.Pen.Color;
  annot2.Shape.Color := cursor2.Pen.Color;
  annot1.Shape.Transparency := 50;
  annot2.Shape.Transparency := 50;
  annot1.Shape.Shadow.Visible := false;
  annot2.Shape.Shadow.Visible := false;
  cursor1.OnChange := ChartTool1Change;
  cursor2.OnChange := ChartTool2Change;

  Chart1.Draw;
  annot1.Top := Chart1.ChartRect.Top;
  annot2.Top := Chart1.ChartRect.Top;
  cursor1.XValue := Chart1.Axes.Bottom.Minimum;
  cursor2.XValue := Chart1.Axes.Bottom.Maximum;
end;


procedure TForm1.ChartTool1Change(Sender: TCursorTool; x, y: Integer;
  const XValue, YValue: Double; Series: TChartSeries; ValueIndex: Integer);
begin
  annot1.Left := x;
end;

procedure TForm1.ChartTool2Change(Sender: TCursorTool; x, y: Integer;
  const XValue, YValue: Double; Series: TChartSeries; ValueIndex: Integer);
begin
  annot2.Left := x;
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

PoLabs
Newbie
Newbie
Posts: 28
Joined: Wed Jun 06, 2007 12:00 am

Re: Initial position of TCursorTool

Post by PoLabs » Fri Jul 17, 2009 10:34 am

Hi,

thank you very much. It realy helped me a lot. I am very grateful for help.

I have another question. When I move cursor I have XValue of it. How can I get YValue of some series according to XValue of cursor. Now I am trying with

Ycoord := Series.CalcYPosValue(Cursor.XValue); // get y coord of XValue of cursor
Result := Series.YScreenToValue(Ycoord);


but it doesn't seem to be ok, values are different than expected. What am I doing wrong?

Thanks.

Aljosa

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

Re: Initial position of TCursorTool

Post by Yeray » Fri Jul 17, 2009 11:18 am

Hi PoLabs,

Please, take a look at the interpolation example that Narcís posted here
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

PoLabs
Newbie
Newbie
Posts: 28
Joined: Wed Jun 06, 2007 12:00 am

Re: Initial position of TCursorTool

Post by PoLabs » Tue Jul 21, 2009 11:27 am

Hi,

I would like to thank you for your help. I solved problems with your and Narcis help.

Thanks again.

Best regards.

Post Reply