Page 1 of 1

How to use custom labels in TpolarSeries?

Posted: Mon Jan 25, 2016 12:47 pm
by 16576306
Using TPolarSeries in TeeChart 2015, how to replace the original circleLabels at 0, 90, 180, 270 degrees with custom labels?

Re: How to use custom labels in TpolarSeries?

Posted: Mon Jan 25, 2016 2:07 pm
by yeray
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;

Re: How to use custom labels in TpolarSeries?

Posted: Tue Jan 26, 2016 5:14 am
by 16576306
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

Re: How to use custom labels in TpolarSeries?

Posted: Tue Jan 26, 2016 8:19 am
by yeray
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;

Re: How to use custom labels in TpolarSeries?

Posted: Wed Feb 24, 2016 7:45 am
by 16576306
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).

Re: How to use custom labels in TpolarSeries?

Posted: Wed Feb 24, 2016 9:31 am
by yeray
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;

Re: How to use custom labels in TpolarSeries?

Posted: Thu Feb 25, 2016 5:12 am
by 16576306
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.

Re: How to use custom labels in TpolarSeries?

Posted: Fri Feb 26, 2016 3:48 pm
by yeray
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;