Creating series useing Mouse

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
xavier
Newbie
Newbie
Posts: 2
Joined: Mon Jun 11, 2001 4:00 am

Creating series useing Mouse

Post by xavier » Wed Sep 08, 2004 8:10 pm

Hi
I use the chart with the tpolarseries object.
One serie is set to initialialize the tchart and make it visible.
I'd like to use mouse to click on the chart (not necessary on a serie ), trap the screen x,y coordinates and transform them to an angle and radius. I may be able to create a new serie with one point on the clicked position of the chart.
Is teechart abled to do this ?
may i have a sample ?

Marjan
Site Admin
Site Admin
Posts: 745
Joined: Fri Nov 07, 2003 5:00 am
Location: Slovenia
Contact:

Post by Marjan » Fri Sep 10, 2004 10:03 am

Hi.
I'd like to use mouse to click on the chart (not necessary on a serie ), trap the screen x,y coordinates and transform them to an angle and radius.
You'll have to manually calculate current screen position radius and angle. This can be done by transforming values from screen coordinates to real axis balues. I think the example is good for circled and also for non circled (x radius <> y radius) case:

Code: Select all

function PointToRadius(ASeries : TCustomPolarSeries; X,Y: Integer): double;
var dx,dy: double;
begin
  With ASeries.GetVertAxis, ASeries do
  begin
    if (Maximum-Minimum) <> 0.0 then
    begin
      dx := x-CircleXCenter;
      dx := dx*(Maximum-Minimum)/XRadius;
      dy := y-CircleYCenter;
      dy := dy*(Maximum-Minimum)/YRadius;
      Result := Sqrt(dx*dx+dy*dy)+Minimum;
    end
    else Result := 0.0;
  end;
end;


procedure TForm1.FormCreate(Sender: TObject);
begin
  Series1.FillSampleValues(10);
end;

procedure TForm1.Chart1MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
var a,r: double;
begin
  a := 180.0*Series1.PointToAngle(X,Y)/3.1416;
  r := PointToRadius(Series1,X,Y);
  Chart1.Title.Text.Clear;
  Chart1.Title.Text.Add('radius='+FormatFloat('0.00',r)
    +' angle='+FormatFloat('0.00',a));
end;
PS : I'll also add this to TCircledSeries as public method so that all circles series can use this method in the future.
Marjan Slatinek,
http://www.steema.com

Post Reply