How to use custom labels in TpolarSeries?

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
sripe
Newbie
Newbie
Posts: 26
Joined: Thu Sep 10, 2015 12:00 am

How to use custom labels in TpolarSeries?

Post by sripe » Mon Jan 25, 2016 12:47 pm

Using TPolarSeries in TeeChart 2015, how to replace the original circleLabels at 0, 90, 180, 270 degrees with custom labels?

Yeray
Site Admin
Site Admin
Posts: 9612
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: How to use custom labels in TpolarSeries?

Post by Yeray » Mon Jan 25, 2016 2:07 pm

Hello,

You can use the TPolarSeries' OnGetCircleLabel event for that. Ie:

Code: Select all

procedure TForm1.PolarGetCircleLabel(Sender:TCustomPolarSeries; const Angle:Double;
                             Index:Integer; var Text:String);
begin
  if Text='40°' then
    Text:='this was 40°';
end;
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

sripe
Newbie
Newbie
Posts: 26
Joined: Thu Sep 10, 2015 12:00 am

Re: How to use custom labels in TpolarSeries?

Post by sripe » Tue Jan 26, 2016 5:14 am

Yes, it works. When Series1 exists, we can use the following procedure:
procedure TForm1.Series1GetCircleLabel(Sender: TCustomPolarSeries; const Angle: Double; Index: Integer; var Text: string);
begin
if Text = '40°' then
Text := 'This was 40°';
end;

But, if I create Series dynamically with codes, where to add and how to use the GetCircleLabel procedure? Would you like to give me an example?
Best Regards,
Xiushan

Yeray
Site Admin
Site Admin
Posts: 9612
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: How to use custom labels in TpolarSeries?

Post by Yeray » Tue Jan 26, 2016 8:19 am

Hello,

To assign an event at runtime you just have to declare the method at the top, as the others. Note the method needs to declare the same parameter types than the event expects. Then, you can assign the event to the series. Ie:

Code: Select all

  private
    { Private declarations }
    procedure Series1GetCircleLabel(Sender: TCustomPolarSeries; const Angle: Double; Index: Integer; var Text: string);
//...
procedure TForm1.FormCreate(Sender: TObject);
begin
  with Chart1.AddSeries(TPolarSeries) as TPolarSeries do
  begin
    FillSampleValues;
    OnGetCircleLabel:=Series1GetCircleLabel;
  end;
end;

procedure TForm1.Series1GetCircleLabel(Sender: TCustomPolarSeries; const Angle: Double; Index: Integer; var Text: string);
begin
  if Text = '40°' then
    Text := 'This was 40°';
end;
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

sripe
Newbie
Newbie
Posts: 26
Joined: Thu Sep 10, 2015 12:00 am

Re: How to use custom labels in TpolarSeries?

Post by sripe » Wed Feb 24, 2016 7:45 am

How to display Axis Labels at every Ticks?
Although I change the Label’s style and margins as far as possible, the Axis Labels do not display as crowded as expected (they are too sparse or few).
Attachments
www.jpg
www.jpg (56.57 KiB) Viewed 9592 times
w2.jpg
w2.jpg (59.62 KiB) Viewed 9591 times
w1.jpg
w1.jpg (59.3 KiB) Viewed 9597 times

Yeray
Site Admin
Site Admin
Posts: 9612
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: How to use custom labels in TpolarSeries?

Post by Yeray » Wed Feb 24, 2016 9:31 am

Hello,

You can modify the Increment:

Code: Select all

GetVertAxis.Increment:=200;
However, if there isn't space for all the labels to be drawn, the circular grid will be drawn according to that Increment but the labels won't match.
In that case, you try setting a smaller font. Ie:

Code: Select all

  Chart1.Axes.Bottom.LabelsFont.Size:=7;
  Chart1.Axes.Top.LabelsFont.Size:=7;
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

sripe
Newbie
Newbie
Posts: 26
Joined: Thu Sep 10, 2015 12:00 am

Re: How to use custom labels in TpolarSeries?

Post by sripe » Thu Feb 25, 2016 5:12 am

It seems that the labels arrangement on the BottomAxis not only relate to the BottomAxis component properties, but also relate to the CircleLabels properties. Sometimes, changing GetVertAxis.Increment or LabelsFont.Size do not get satisfied results. Generally, we expect to arrange the labels on the radial axes and the Radar/Polar circle, respectively. That is to say, the label’s properties on the radial axes and the Radar/Polar circle may be different. Do you have any good solutions to arrange the labels on the radial axes closely? Thanks a lot.

Yeray
Site Admin
Site Admin
Posts: 9612
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: How to use custom labels in TpolarSeries?

Post by Yeray » Fri Feb 26, 2016 3:48 pm

Hello,

If I understand the problem correctly, you can use custom labels to manually place the labels you want. Ie:

Code: Select all

uses TeePolar;

procedure TForm1.FormCreate(Sender: TObject);
var i, tmp, tmpInc: Integer;
begin
  Chart1.View3D:=false;
  Chart1.Legend.Visible:=false;

  Chart1.Gradient.Visible:=false;
  with Chart1.AddSeries(TPolarSeries) as TPolarSeries do
  begin
    FillSampleValues;
    Pointer.Visible:=false;
    Brush.Clear;
    Pen.Color:=Color;
    CircleBrush.Clear;
  end;

  Chart1.Axes.Bottom.LabelsFont.Size:=7;
  Chart1.Axes.Top.LabelsFont.Size:=7;

  Chart1.Draw;

  with Chart1.Axes.Top do
  begin
    tmpInc:=Round((Chart1[0].MaxYValue-Chart1[0].MinYValue)/5);
    Items.Clear;
    for i:=0 to 4 do
    begin
      tmp:=Round(Minimum+(i*tmpInc));
      Items.Add(tmp, IntToStr(tmp));
    end;
  end;
end;
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Post Reply