I have a line series where the bottom (x) axis is defined as DateTime. Within the Chart.MouseMove event I would like to get the index of the line series. The MouseMove gives me x/y coordinates but I see no method to transform the these into the respective index.
Something like a (fictive) Chart.BottomAxis.CalcXValueIndex(X) method.
Any idea?
Retrieving (x) value index of mouse position.
-
- Newbie
- Posts: 6
- Joined: Mon Jun 27, 2011 12:00 am
Re: Retrieving (x) value index of mouse position.
Hi,
The Axes have the CalcPosValue and CalcPosPoint functions.
- CalcPosValue takes a Double (value in the axis) and returns an Integer (pixel position).
- CalcPosPoint takes an Integer (pixel position) and returns a Double (value in the axis).
The Axes have the CalcPosValue and CalcPosPoint functions.
- CalcPosValue takes a Double (value in the axis) and returns an Integer (pixel position).
- CalcPosPoint takes an Integer (pixel position) and returns a Double (value in the axis).
Best Regards,
Yeray Alonso Development & Support Steema Software Av. Montilivi 33, 17003 Girona, Catalonia (SP) | |
Please read our Bug Fixing Policy |
-
- Newbie
- Posts: 6
- Joined: Mon Jun 27, 2011 12:00 am
Re: Retrieving (x) value index of mouse position.
CalcPosPoint returns the DateTime value of the x axis. I am looking for the ItemIndex within the series in order to access the underlying data object.
e.g. Series values
ItemIndex x-Value y-value
0 01.01.2013 35.00
1 02.01.2013 38.00
2 03.01.2013 37.50
3 04.01.2013 39.00
4 05.01.2013 38.80
e.g. Series values
ItemIndex x-Value y-value
0 01.01.2013 35.00
1 02.01.2013 38.00
2 03.01.2013 37.50
3 04.01.2013 39.00
4 05.01.2013 38.80
Re: Retrieving (x) value index of mouse position.
Hi Christian,
Given an X pixel, a series may have or may not have a value drawn in that x-pixel. You could loop your series values to see if any of its values are drawn in a given X pixel. Ie:
You may also want to find the nearest point given an x pixel position. A complete example of how to do something similar to this could be found in the features demo project, concretely in the "All features\Welcome !\Chart styles\Standard\Line(Strip)\Interpolating Line series"
Given an X pixel, a series may have or may not have a value drawn in that x-pixel. You could loop your series values to see if any of its values are drawn in a given X pixel. Ie:
Code: Select all
for i:=0 to Chart1[0].Count-1 do
if (Chart1[0].CalcXPos(i) = X) then
valueIndex:=i;
Best Regards,
Yeray Alonso Development & Support Steema Software Av. Montilivi 33, 17003 Girona, Catalonia (SP) | |
Please read our Bug Fixing Policy |
-
- Newbie
- Posts: 6
- Joined: Mon Jun 27, 2011 12:00 am
Re: Retrieving (x) value index of mouse position.
Thank you. With that info I could write a helper function for that task. If someone has a similar problem here it is...
Code: Select all
function GetXValueIndex(ASeries: TCustomLineSeries; X: Integer): Integer;
var
i: Integer;
Value: Double;
begin
Value := ASeries.ParentChart.BottomAxis.CalcPosPoint(X);
for i := ASeries.FirstValueIndex to ASeries.LastValueIndex do begin
if ASeries.XValue[i] > Value then begin
Result := i;
Exit;
end;
end;
// Nothing found so return the last index
Result := ASeries.LastValueIndex;
end;