Initial position of TCursorTool
Initial position of TCursorTool
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.
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.
Re: Initial position of TCursorTool
Hi PoLabs,
Please, take a look at the following example. Everything seems to work as expected:
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.
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;
Best Regards,
Yeray Alonso Development & Support Steema Software Av. Montilivi 33, 17003 Girona, Catalonia (SP) | |
Please read our Bug Fixing Policy |
Re: Initial position of TCursorTool
Dummy me!! I am so deep into it so I just need to step on step back to see the solution.
Thank you very much.
Best regards.
Thank you very much.
Best regards.
Re: Initial position of TCursorTool
One more question.
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
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
Re: Initial position of TCursorTool
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:
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,
Yeray Alonso Development & Support Steema Software Av. Montilivi 33, 17003 Girona, Catalonia (SP) | |
Please read our Bug Fixing Policy |
Re: Initial position of TCursorTool
Thank you very much. It works!
Best regards,
Aljosa
Best regards,
Aljosa
Re: Initial position of TCursorTool
Again me...
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.
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.
Re: Initial position of TCursorTool
Hi BR,
This is the one:
This is the one:
Code: Select all
tChart1.Axes.Bottom.CalcXPosValue();
Don't worry. We are here for that!PoLabs wrote:Again me...
Best Regards,
Yeray Alonso Development & Support Steema Software Av. Montilivi 33, 17003 Girona, Catalonia (SP) | |
Please read our Bug Fixing Policy |
Re: Initial position of TCursorTool
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
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
Re: Initial position of TCursorTool
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:
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,
Yeray Alonso Development & Support Steema Software Av. Montilivi 33, 17003 Girona, Catalonia (SP) | |
Please read our Bug Fixing Policy |
Re: Initial position of TCursorTool
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
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
Re: Initial position of TCursorTool
Best Regards,
Yeray Alonso Development & Support Steema Software Av. Montilivi 33, 17003 Girona, Catalonia (SP) | |
Please read our Bug Fixing Policy |
Re: Initial position of TCursorTool
Hi,
I would like to thank you for your help. I solved problems with your and Narcis help.
Thanks again.
Best regards.
I would like to thank you for your help. I solved problems with your and Narcis help.
Thanks again.
Best regards.