Labels on TRoseSeries

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
peterlepan
Newbie
Newbie
Posts: 10
Joined: Thu Mar 06, 2014 12:00 am

Labels on TRoseSeries

Post by peterlepan » Wed Jun 10, 2015 1:54 pm

Hi,

I have an TRoseSeries-chart and want to label the segments with labels. How can I position the labels with a larger margin and give them arrows so that every label points to its segment?
Is it possible to have a larger margin from the labels to the chart at the middle of the right and left side of the chart?
If I use Marks instead of the labels, the marks are positioned on my chart, the segments are partially hidden.
rose.jpg
TRoseSeries with labels
rose.jpg (257.53 KiB) Viewed 9823 times
marks.jpg
marks instead of the labels
marks.jpg (237.79 KiB) Viewed 9810 times
Kind regards

Peter

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

Re: Labels on TRoseSeries

Post by Narcís » Thu Jun 11, 2015 8:57 am

Hi Peter,
peterlepan wrote: How can I position the labels with a larger margin and give them arrows so that every label points to its segment?
It's a little bit tricky but possible with custom marks position as shown in the code snippet below. Also find attached the complete example project.

Code: Select all

procedure TForm1.CustomLabelsPosition;
const MarksOffset = 30;
var
  i : Integer;
  P : TPoint;
  Radius  : TPoint;
  Angle : TChartValue;
begin
  Radius:=TeePoint(Rose.XRadius + MarksOffset, Rose.YRadius + MarksOffset);
  
  for i:=0 to Rose.Marks.Positions.Count-1 do
  begin
    Angle:=DegToRad(Rose.AngleValues[i]);

    if Assigned(Rose.Marks.Positions[i]) then
    begin
      Rose.AngleToPos(Angle, Radius.X, Radius.Y, P.X, P.Y);
      Rose.Marks.Positions[i].Custom:=True;
      Rose.Marks.Positions[i].LeftTop.X:=P.X;
      Rose.Marks.Positions[i].LeftTop.Y:=P.Y;
      Rose.Marks.Positions[i].ArrowFrom.X:=P.X;
      Rose.Marks.Positions[i].ArrowFrom.Y:=P.Y;
    end;
  end;

  Rose.Repaint;
  Rose.RefreshSeries;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Rose:=TRoseSeries.Create(Self);
  Rose.FillSampleValues(); 
  Rose.AngleLabels.Visible:=False;
  Rose.Marks.Visible:=True;
  //Rose.Marks.Transparent:=True;
  Rose.Marks.Arrow.Visible:=True;

  Chart1.ClipPoints:=False;
  Chart1.View3D:=False;
  Chart1.AddSeries(Rose);

  Chart1.Draw;
  CustomLabelsPosition;
  Chart1.Draw;
end;
peterlepan wrote: Is it possible to have a larger margin from the labels to the chart at the middle of the right and left side of the chart?
Yes, you can modify that depending on angle values, for example:

Code: Select all

procedure TForm1.CustomLabelsPosition;
const MarksOffset = 30;
var
  i : Integer;
  P : TPoint;
  Radius  : TPoint;
  Angle : TChartValue;
begin
  Radius:=TeePoint(Rose.XRadius + MarksOffset, Rose.YRadius + MarksOffset);

  for i:=0 to Rose.Marks.Positions.Count-1 do
  begin
    Angle:=Rose.AngleValues[i];

    if (Angle<45) or ((Angle>135) and (Angle<225)) or (Angle>315) then
    begin
      Radius.X:=Radius.X + 5;
      Radius.Y:=Radius.Y + 5;
    end;

    Angle:=DegToRad(Angle);

    if Assigned(Rose.Marks.Positions[i]) then
    begin
      Rose.AngleToPos(Angle, Radius.X, Radius.Y, P.X, P.Y);
      Rose.Marks.Positions[i].Custom:=True;
      Rose.Marks.Positions[i].LeftTop.X:=P.X;
      Rose.Marks.Positions[i].LeftTop.Y:=P.Y;
      Rose.Marks.Positions[i].ArrowFrom.X:=P.X;
      Rose.Marks.Positions[i].ArrowFrom.Y:=P.Y;
    end;
  end;

  Rose.Repaint;
  Rose.RefreshSeries;
end;
Attachments
RoseCustomLabels.zip
(2.77 KiB) Downloaded 600 times
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

peterlepan
Newbie
Newbie
Posts: 10
Joined: Thu Mar 06, 2014 12:00 am

Re: Labels on TRoseSeries

Post by peterlepan » Fri Jun 12, 2015 12:55 am

Hi Narcís,
thank you for your answer, but the solutions are really "tricky".
If I use labels and position them with a large margin, the right half of the chart is very nice, but look at the left side! Why are the labels on the left side so confused? Can't they look like the labels on the right side?
Have you an idea for this problem? I wish my labels look like the beams from the sun ;-) and the chart is the sun
rose_label.jpg
rose_label.jpg (291.85 KiB) Viewed 9766 times
Sincerely yours

Peter

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

Re: Labels on TRoseSeries

Post by Narcís » Fri Jun 12, 2015 9:03 am

Hi Peter,
peterlepan wrote: If I use labels and position them with a large margin, the right half of the chart is very nice, but look at the left side! Why are the labels on the left side so confused? Can't they look like the labels on the right side?
Have you an idea for this problem?
Can you please attach a simple example project we can run "as-is" to reproduce the problem here?
peterlepan wrote: I wish my labels look like the beams from the sun ;-) and the chart is the sun
:D

Thanks in advance.
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

peterlepan
Newbie
Newbie
Posts: 10
Joined: Thu Mar 06, 2014 12:00 am

Re: Labels on TRoseSeries

Post by peterlepan » Fri Jun 12, 2015 3:33 pm

Hi Narcís,

my problem was, that some of the labels where too long. Now, we have shorted the labels to three signs and it looks fine. The only caveat now is a little offset on top and bottom of the chart labels. Thats why the label text is left-aligned. Is it possible, to create an ideal cirlce from the labels?

With the new three-signed-labels, I need a legend beside the chart, with the complete label-text for the shortened label. How can I do this with the standard legend? Can I create a new invisible series with the long label texts and the three sign short labes? Or have I to print the legend by myself in the AfterDraw event handler?

Thank you

Peter

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

Re: Labels on TRoseSeries

Post by Narcís » Mon Jun 15, 2015 7:48 am

Hi Peter,
peterlepan wrote: Is it possible, to create an ideal cirlce from the labels?
I'm not sure about what you mean here. Could you please attach a simple example project we can run "as-is" to reproduce the problem here?
peterlepan wrote: With the new three-signed-labels, I need a legend beside the chart, with the complete label-text for the shortened label. How can I do this with the standard legend? Can I create a new invisible series with the long label texts and the three sign short labes? Or have I to print the legend by myself in the AfterDraw event handler?
You can have the standard legend with the full text. You could shorten labels in the OnGetMarkText event. Alternatively, you could do something similar in the OnGetLegendText event. Another option is using the Custom Legend tool. You'll find an example at All Features\Welcome!\Tools\Custom Legend in the new features demo, available at TeeChart's program group.
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