Page 1 of 1
Get onMouseMove Labels instead of Values
Posted: Wed Oct 10, 2007 11:20 am
by 9349520
i have on event procedure to get value of y mouse poistion
Code: Select all
FormatFloat('# ###,##0',(Round(aChart.CustomAxes.Items[i].CalcPosPoint(Y)))
but i don't have idea how to get on the same event value of labels when axis.Labelstyle = talText
tahnks in advance for any help
Posted: Wed Oct 10, 2007 12:03 pm
by narcis
Hi guzial,
You can try doing something like this:
Code: Select all
procedure TForm1.Chart1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
var YVal: Double;
Index: Integer;
begin
YVal := Chart1.Axes.Left.CalcPosPoint(Y);
Index := Series1.YValues.Locate(YVal);
if Index <>-1 then
Chart1.Title.Text[0]:=Series1.Labels[Index];
end;
Hope this helps!
Posted: Wed Oct 10, 2007 12:20 pm
by 9349520
it is possible to show text not using series but just mouse position and axis?
Posted: Wed Oct 10, 2007 12:35 pm
by narcis
Hi guzial,
You can use custom labels as shown in the All Features\Welcome!\Axes\Labels\Custom Labels example in the features demo. Which can be found at TeeChart's program group. An then obtain labels like Chart1.Axes.Left.Items[Index].Text. However, I can't think of a way to relate them to the mouse position at the moment.
Posted: Thu Oct 11, 2007 7:51 am
by 9349520
ok so if i do
Code: Select all
Axis.Items.Add(0, 'AAA');
Axis.Items.Add(1, 'BBB');
and then i know only value for example 0 or 1 it is not possible to get text for this values ??
Posted: Thu Oct 11, 2007 9:22 am
by narcis
Hi guzial,
You should be able to do something as in the code below. However I've found that
Chart1.Axes.Left.Items.Value doesn't store the correct value and therefore this code snippet doesn't work. I've added this defect (TV52012517) to our bug list to be fixed for future releases.
Code: Select all
procedure TForm1.Chart1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
var YVal: Double;
i: Integer;
begin
YVal := Chart1.Axes.Left.CalcPosPoint(Y);
for i:=0 to Chart1.Axes.Left.Items.Count - 1 do
begin
if Chart1.Axes.Left.Items[i].Value = YVal then
Chart1.Title.Text[0]:=Chart1.Axes.Left.Items[i].Text;
end;
end;
Posted: Fri Nov 16, 2007 9:33 am
by narcis
Hi guzial,
As an update, one of my colleagues pointed me out that TV52012517 is not a bug. When comparing floating point values you should specify a tolerance. For example, this works fine:
Code: Select all
uses Math, Types;
procedure TForm1.FormCreate(Sender: TObject);
var i: Integer;
begin
Chart1.Axes.Left.Items.Clear;
for i:=-5 to 5 do
begin
Series1.Add(i);
Chart1.Axes.Left.Items.Add(i, 'Point ' + IntToStr(i));
end;
end;
procedure TForm1.Chart1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
var YVal: Double;
i: Integer;
begin
YVal := Chart1.Axes.Left.CalcPosPoint(Y);
for i:=0 to Chart1.Axes.Left.Items.Count - 1 do
begin
if CompareValue(Chart1.Axes.Left.Items[i].Value,YVal,0.1)=EqualsValue then
Chart1.Title.Text[0]:=Chart1.Axes.Left.Items[i].Text;
end;
end;