Hi ChZiegelt,
If you want to continue using your cursor tools to update the state of each point, I suggest you to use a table to store the state of each point (in order to allow more than one point to stay in the same state). And update this table at OnChartTool change event. Note that in the following example I use the labels list as states table.
Then I use two global variables. One to choose which tool (or state) is going to be moved (or set) and the other to choose which the series point.
And after assigning them to the desired values, you should call the previous mentioned event in order to update the states table and you could do this, for example, moving the cursor tool to the point.
And finally, I draw the state identifier lines in OnAfterDraw event because I have all the states saved and they don't depend on Cursor tools position or activation/deactivation.
Code: Select all
var
Form1: TForm1;
ActualIndex: Integer;
ActualTool: Integer;
...
procedure TForm1.ChartTool1Change(Sender: TCursorTool; x, y: Integer;
const XValue, YValue: Double; Series: TChartSeries; ValueIndex: Integer);
begin
if ActualIndex <> -1 then
begin
if Sender=ChartTool1 then
Series1.Labels[ActualIndex]:='A';
if Sender=ChartTool2 then
Series1.Labels[ActualIndex]:='B';
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
ChartTool1.ScopeStyle := scsEmpty;
ChartTool1.Style := cssScopeOnly;
ChartTool1.FollowMouse := false;
ChartTool2.ScopeStyle := scsEmpty;
ChartTool2.Style := cssScopeOnly;
ChartTool2.FollowMouse := false;
ChartTool1.Active:=false;
ChartTool2.Active:=false;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
ActualTool := 1;
ActualIndex := 8;
(Chart1.Tools.Items[ActualTool-1] as TCursorTool).XValue := Series1.XValue[ActualIndex];
(Chart1.Tools.Items[ActualTool-1] as TCursorTool).YValue := Series1.YValue[ActualIndex];
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
ActualTool := 2;
ActualIndex := 5;
(Chart1.Tools.Items[ActualTool-1] as TCursorTool).XValue := Series1.XValue[ActualIndex];
(Chart1.Tools.Items[ActualTool-1] as TCursorTool).YValue := Series1.YValue[ActualIndex];
end;
procedure TForm1.Chart1AfterDraw(Sender: TObject);
var i, xpixels, ypixels: Integer;
begin
for i:=0 to Chart1[0].Count -1 do
begin
if Chart1[0].Labels[i] = 'A' then
begin
xpixels := Chart1.Axes.Bottom.CalcXPosValue(Chart1[0].XValue[i]);
ypixels := Chart1.Axes.Left.CalcYPosValue(Chart1[0].YValue[i]);
Chart1.Canvas.Pen.Color := clRed;
Chart1.Canvas.Line(xpixels-10,ypixels,xpixels+10,ypixels);
Chart1.Canvas.Line(xpixels,ypixels-10,xpixels,ypixels+10);
end;
if Chart1[0].Labels[i] = 'B' then
begin
xpixels := Chart1.Axes.Bottom.CalcXPosValue(Chart1[0].XValue[i]);
ypixels := Chart1.Axes.Left.CalcYPosValue(Chart1[0].YValue[i]);
Chart1.Canvas.Pen.Color := clWhite;
Chart1.Canvas.Line(xpixels-10,ypixels,xpixels+10,ypixels);
Chart1.Canvas.Line(xpixels,ypixels-10,xpixels,ypixels+10);
end;
end;
end;