Hello Steve,
I use cursors with VCL in WIN32 and do not know if the following applies to the .NET version. When the cursor moves, is the matching data point being searched for ? If so, I believe the VCL version always starts it search from the begiining of the data values list. It seems a quicker approach would be to begin from the previous data index and search above and below from there, assuming the points are ordered.
The .NET code and the VCL code is to all extents and purposes indentical in this area. The data point, that is, the axis xvalue and axis yvalue, is being calculated in a private method called CalcValuePositions() which is invoked on every mousemove (when FollowMouse=true). This method, in turn, invokes the Axis.CalcPosPoint() method of the respective vertical and horizontal axes which calculates the point using very simply pixel calculations on the axis length and range instead of trailing through the ValueLists to calculate the value.
Alos, if the cursor Snap is true, then use the OnSnapChange event instead of OnChange so the cursor event fires (and thus requires the chart to be redrawn) only when the data point to which it is associated actualy changes, and not when the pixel on the chart changes.
Well, firstly neither the invoking of the OnSnapChange event nor the invoking of the OnChange event cause a Chart Repaint. I think that the OnSnapChange event is only being called when the snap actually changes and not when the mouse pixel position changes, as can be seen in this code example (teechart vcl v8 beta code):
- Code: Select all
procedure TForm1.ChartTool1Change(Sender: TCursorTool; x, y: Integer;
const XValue, YValue: Double; Series: TChartSeries; ValueIndex: Integer);
begin
Inc(count); //count is a private form variable
Label1.Caption := IntToStr(count);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
InitializeChart;
end;
procedure TForm1.InitializeChart;
var
Series : TLineSeries;
Tool : TCursorTool;
begin
Series := TLineSeries.Create(Self);
Series.ParentChart := Chart1;
Series.FillSampleValues(5);
Tool := TCursorTool.Create(Self);
Tool.ParentChart := Chart1;
Tool.Series := Series;
Tool.Style := cssVertical;
Tool.FollowMouse := true;
Tool.Snap := true;
Tool.OnSnapChange := ChartTool1Change;
end;