Get onMouseMove Labels instead of Values

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
guzial
Newbie
Newbie
Posts: 7
Joined: Mon Mar 12, 2007 12:00 am

Get onMouseMove Labels instead of Values

Post by guzial » Wed Oct 10, 2007 11:20 am

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

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Wed Oct 10, 2007 12:03 pm

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!
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

guzial
Newbie
Newbie
Posts: 7
Joined: Mon Mar 12, 2007 12:00 am

Post by guzial » Wed Oct 10, 2007 12:20 pm

it is possible to show text not using series but just mouse position and axis?

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Wed Oct 10, 2007 12:35 pm

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.
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

guzial
Newbie
Newbie
Posts: 7
Joined: Mon Mar 12, 2007 12:00 am

Post by guzial » Thu Oct 11, 2007 7:51 am

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 ??

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Thu Oct 11, 2007 9:22 am

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;
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Fri Nov 16, 2007 9:33 am

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;
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Post Reply