Alternative TGauge labels

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
bdw
Advanced
Posts: 130
Joined: Mon Mar 07, 2005 5:00 am
Location: New Zealand
Contact:

Alternative TGauge labels

Post by bdw » Thu May 19, 2005 9:13 am

Hi,
We have TChart 7.04 VCL. I was trying to display alternative axis labels on the TGauge graph but have had no luck. With the TLineSeries this could be done with code similar to :-
TChartAxis *axis = graph_->Axes->Right;
axis->Items->Clear(); // remove all custom labels
// add custom labels
axis->Items->Add(0.0, "N");
This does not seem to work with the TGauge even if you get the TGaugeSeries.Axis.......
TIA,
Brett

Pep
Site Admin
Site Admin
Posts: 3299
Joined: Fri Nov 14, 2003 5:00 am
Contact:

Post by Pep » Thu May 26, 2005 10:23 am

Hi Brett,

for the moment the only way to do this (using Gauge Series) is by setting the Left axis labels visible to False (which are the labels of the Gauge) and then use the Canvas techniques to draw text on the Canvas.

This feature is on our wish list to be considered for further releases.

bdw
Advanced
Posts: 130
Joined: Mon Mar 07, 2005 5:00 am
Location: New Zealand
Contact:

Post by bdw » Thu May 26, 2005 8:35 pm

Thanks Pep for the reply.

It took me a while to work out but your suggestion was the work around I was using.

I have it working to some extent at the present time, however I seem to strike a probelm when I try and use the AngleToPos() function and the RotationAnlge is not set to 90 or 270, can someone explain this function ?

The angle passed to AngleToPos() is a radian value but I need to make it negative to display correctly at 90 and 270.........at any other rotation angle the values are all over the place......

Thanks for any help,
Brett

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 May 27, 2005 7:29 am

Hi Brett,
I have it working to some extent at the present time, however I seem to strike a probelm when I try and use the AngleToPos() function and the RotationAnlge is not set to 90 or 270, can someone explain this function ?
According to TeeChart help files:

procedure AngleToPos(Const Angle, AXRadius, AYRadius: Double; Var X, Y: Integer);

Description
The AngleToPos functions returns the exact Screen position for a given pair of Angle and Radius values.

Angles must be expressed in radians from 0 to 2*PI. Radius parameter is in number of pixels.
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

bdw
Advanced
Posts: 130
Joined: Mon Mar 07, 2005 5:00 am
Location: New Zealand
Contact:

Post by bdw » Wed Jun 01, 2005 2:42 am

Hi,
I guess I didn't explain myself enough, I was aware of the help file definition of the AngleToPos() function. My question is why do I need to put in a negative angle to get the correct screen coordinate when the RotationAngle propertie is set to 90 or 270 degrees ?

When its not a 90 or 270 degrees I don't get the screen coordinate that corresponds to the angle put into the AngleToPos() function ?

Thanks for you help,
Brett.

Pep
Site Admin
Site Admin
Posts: 3299
Joined: Fri Nov 14, 2003 5:00 am
Contact:

Post by Pep » Thu Jun 16, 2005 8:32 am

Hi Brett,

using similar code to the following code (which is the one used to show the labels) you should be to draw your custom labels :

Code: Select all

Procedure Tform1.DrawAngleLabel(Angle:Double; AIndex:Integer);
 { MS : 5.02 - replaced old code }
    var X         : Integer;
        Y         : Integer;
        tmpHeight : Integer;
        tmpWidth  : Integer;
        AngleRad  : Double;
        tmpSt     : String;
        tmpXRad   : Integer;
        tmpYRad   : Integer;
        tmpMult   : Integer;
        tmpMargin : Double;
    begin
      With Chart1.Canvas do
      begin
//        AssignFont(CircleLabelsFont);
        tmpHeight:=FontHeight;
        if Angle>=360 then Angle:=Angle-360;

        tmpSt:=  GetCircleLabel(Angle,AIndex);

        tmpXRad:=XRadius;
        tmpYRad:=YRadius;

//          tmpMargin:=LabelsMargin/100.0;

        Inc(tmpXRad,Round(tmpXRad*tmpMargin));
        Inc(tmpYRad,Round(tmpYRad*tmpMargin));


        AngleToPos(Angle*PiDegree,tmpXRad,tmpYRad,X,Y);

        Angle:=Angle+RotationAngle;
        AngleRad:=Angle*PiDegree;

        if CircleLabelsRotated then
        begin
          if (Angle>90) and (Angle<270) then
             tmpMult:= 1  { right aligned }
          else
             tmpMult:=-1; { left aligned }

          Inc(X, tmpMult*Round(0.5*tmpHeight*Sin(AngleRad)));
          Inc(Y, tmpMult*Round(0.5*tmpHeight*Cos(AngleRad)));
        end;

        if Angle>=360 then Angle:=Angle-360;

        if FCircleLabelsRot then
        begin
          if (Angle>90) and (Angle<270) then
          begin
            TextAlign:=TA_RIGHT;
            Angle:=Angle+180;
          end
          else TextAlign:=TA_LEFT;

          RotateLabel3D(X,Y,EndZ,tmpSt,Angle);
        end
        else
        begin
          if (Angle=0) or (Angle=180) then Dec(Y,tmpHeight div 2)
          else
          if (Angle>0) and (Angle<180) then Dec(Y,tmpHeight);
          if (Angle=90) or (Angle=270) then TextAlign:=ta_Center
          else
          begin
            if FCircleLabelsInside then
               if (Angle>90) and (Angle<270) then TextAlign:=ta_Left
                                             else TextAlign:=ta_Right
            else
               if (Angle>90) and (Angle<270) then TextAlign:=ta_Right
                                             else TextAlign:=ta_Left;
          end;

          tmpWidth:=TextWidth('0') div 2;

          if Angle=0 then Inc(x,tmpWidth) else
          if Angle=180 then Dec(x,tmpWidth);

          TextOut3D(X,Y,EndZ,tmpSt);
        end;
      end;
    end;


procedure TForm1.Chart1AfterDraw(Sender: TObject);
begin
while tmpValue<360 do
    begin
      DrawAngleLabel(tmpValue,tmpIndex);
      tmpValue:=tmpValue+tmpIncrement;
      Inc(tmpIndex);
    end;
end;

Post Reply