Showing Series Label Below Each Pie Chart and Mark Position

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
Isaac Alexander
Newbie
Newbie
Posts: 7
Joined: Wed Jul 11, 2007 12:00 am

Showing Series Label Below Each Pie Chart and Mark Position

Post by Isaac Alexander » Fri Aug 03, 2007 10:50 pm

I am using D7 and Tee8.

I have 3 pie series in a single TChart which are displayed horz. I would like to have the series name below each one. Is this possible?

Also, I would like to have the pie marks show up on top of the pie slices. The reason for this is because when marks are displayed, the chart gets shrunken to a point of not being visible. I've tried playing with the mark positions, but it's not going well. Any ideas?

I posted a similar question on the newsgroup, but I noticed that this forum exists.

xxxxxx
Advanced
Posts: 128
Joined: Tue Jun 19, 2007 12:00 am
Location: Russia
Contact:

Post by xxxxxx » Sat Aug 04, 2007 2:23 pm

Hi, Isaac Alexander!
Try to change Series Marks Callout Distance and Length properties to negative like this

Code: Select all

      Marks.Callout.Distance = -11
      Marks.Callout.Length = -9
Seems produces desired effect.
For Legends see e.g. Multiple Legends Demo (Legend_Multi.pas) in Tee8New Demo
PS. Alexander is your name or surname?
Regards, Alexander
=================
TeeChart Pro v8.05, Delphi 5 & Turbo Delphi Professional for Win32., Delphi & C++Builder 2009

Isaac Alexander
Newbie
Newbie
Posts: 7
Joined: Wed Jul 11, 2007 12:00 am

Post by Isaac Alexander » Tue Aug 07, 2007 7:30 pm

9047589 wrote:Try to change Series Marks Callout Distance and Length properties to negative like this

Code: Select all

      Marks.Callout.Distance = -11
      Marks.Callout.Length = -9
Seems produces desired effect.
It helps with moving the mark labels on top of the pie slices, but the margins between each pie series are still huge. It changed a little with the above change. Is there a way to change the margin size that gets reserved for each series marks?
For Legends see e.g. Multiple Legends Demo (Legend_Multi.pas) in Tee8New Demo
That looks like it would work for legends for each series, but I only want the name of the series below each pie. Can it be done the the BeforeDrawValues event with the custom series drawing? If so, is there an example?
PS. Alexander is your name or surname?
Alexander is my last name. Not sure how that got into the signature. I didnt have one set. I put one it.

xxxxxx
Advanced
Posts: 128
Joined: Tue Jun 19, 2007 12:00 am
Location: Russia
Contact:

Post by xxxxxx » Tue Aug 07, 2007 9:42 pm

Hi, Isaac!
10046043 wrote:Is there a way to change the margin size that gets reserved for each series marks?
Do you try to achieve an effect like this
Image?

That looks like it would work for legends for each series, but I only want the name of the series below each pie. Can it be done the the BeforeDrawValues event with the custom series drawing? If so, is there an example?
If you use D7, that was shipped with TeeChart Standard, look at Demos\Teechart\udraw.pas in your Delphi. And I recommend use AfterDraw* events.[/img]
Regards, Alexander
=================
TeeChart Pro v8.05, Delphi 5 & Turbo Delphi Professional for Win32., Delphi & C++Builder 2009

Isaac Alexander
Newbie
Newbie
Posts: 7
Joined: Wed Jul 11, 2007 12:00 am

Post by Isaac Alexander » Tue Aug 07, 2007 11:32 pm

Do you try to achieve an effect like this
Image?
Not really, I'm looking for something more like this.

Current display:

Image

What I want to display:

Image

If you use D7, that was shipped with TeeChart Standard, look at Demos\Teechart\udraw.pas in your Delphi. And I recommend use AfterDraw* events.
That example doesn't seem to show how to dump additional text on the screen.

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

Post by Yeray » Wed Aug 08, 2007 8:25 am

Hi Isaac,

If the Pie Series title is not going to change during execution I suggest you to use annotation tools or labels.

Otherwise, you should use the OnAfterDraw event suggested above.
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

xxxxxx
Advanced
Posts: 128
Joined: Tue Jun 19, 2007 12:00 am
Location: Russia
Contact:

Post by xxxxxx » Wed Aug 08, 2007 9:00 am

10046043 wrote: Image
Obana! ("Wow" in Russian:)
Could you explain how you managed to draw pie series side by side?
Regards, Alexander
=================
TeeChart Pro v8.05, Delphi 5 & Turbo Delphi Professional for Win32., Delphi & C++Builder 2009

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

Post by Marjan » Wed Aug 08, 2007 1:10 pm

Hi.

I think he used OnBeforeDrawValues event (as demonstrated in TeeChart "Multiple Pies" demo) with a little twist:

Code: Select all

procedure TPieMultiple.Series1BeforeDrawValues(Sender: TObject);
begin
  Chart1.ChartRect:=Rect(10,10,Chart1.Width div 3, Chart1.Height - 10);
end;

procedure TPieMultiple.Series2BeforeDrawValues(Sender: TObject);
begin
  Chart1.ChartRect:=Rect(Chart1.Width div 3, 10, 2*(Chart1.Width div 3),Chart1.Height-10);
end;

procedure TPieMultiple.Series3BeforeDrawValues(Sender: TObject);
begin
  Chart1.ChartRect:=Rect(2*(Chart1.Width div 3), 10,Chart1.Width, Chart1.Height-10);
end;
As for series title below each pie, you can draw required text in the Chart OnAfterDraw values. Something like this:

Code: Select all

procedure TForm1.Chart1AfterDraw(Sender: TObject);
var x,y,w: Integer;
  st: String;
  i,tw: Integer;
begin
  With Chart1, Chart1.Canvas do
  begin
    y := Chart1.ChartRect.Bottom-10;
    Font.Style := [fsBold];
    // assume all series are pies in-a-row
    w := Chart1.Width div Chart1.SeriesList.Count;
    for i := 0 to Chart1.SeriesList.Count -1 do
    begin
      tw := TextWidth(Chart1.Series[i].Title);
      x := i*w + (w-tw) div 2;
      TextOut(x,y,Chart1.Series[i].Title);
    end;
  end;
end;
And finally, to reduce the margins between pies, try setting each pie CustomXRadius and CustomYRadius properties to meaningful values. In your case, something like this:

Code: Select all

Series1.CustomXRadius := Chart1.Width div 3 -30;
Series1.CustomYRadius := Series1.CustomXRadius;
//...
BTW, new TeeChart v8 VCL already automatically arranges multiple pie series (in multiple rows/cols).
Marjan Slatinek,
http://www.steema.com

Isaac Alexander
Newbie
Newbie
Posts: 7
Joined: Wed Jul 11, 2007 12:00 am

Post by Isaac Alexander » Wed Aug 08, 2007 6:12 pm

I think he used OnBeforeDrawValues event (as demonstrated in TeeChart "Multiple Pies" demo) with a little twist
You are correct. I used the following code.

Code: Select all

procedure TMyChart.CustomBeforeDrawValues(Sender: TObject);
var
  TempIndex, TempWidth : integer;
begin
  TempIndex := SeriesList.IndexOf(Sender);
  TempWidth := Width div SeriesList.Count;
  ChartRect := Rect(TempWidth * TempIndex, 0, TempWidth * (TempIndex + 1), Height);
end;
As for series title below each pie, you can draw required text in the Chart OnAfterDraw values. Something like this:

Code: Select all

procedure TMyChart.CustomAfterDraw(Sender: TObject);
var
  i, TempTextWidth, TempX, TempY, TempWidth: Integer;
begin
  with Canvas do
  begin
    TempY := ChartRect.Bottom - 15;
    Font.Style := [fsBold];
    // assume all series are pies in-a-row
    TempWidth := Width div SeriesList.Count;
    for i := 0 to SeriesList.Count -1 do
    begin
      if (Series[i] is TCircledSeries) then
      begin
        TempTextWidth := TextWidth(Series[i].Title);
        TempX := (i * TempWidth) + (TempWidth - TempTextWidth) div 2;
        TextOut(TempX, TempY, Series[i].Title);
      end;
    end;
  end;
end;
Thanks. That worked perfectly.
And finally, to reduce the margins between pies, try setting each pie CustomXRadius and CustomYRadius properties to meaningful values. In your case, something like this:
It's working, sort of. I would like the pies to increase in size as the chart form is resized. If I set the Custom Radiuses once, then the pies don't resize. Also, the space between pies shrink, but the space before the first pie does not. The labels for the pies move perfectly, but the pies do not.

Here's the code:

Code: Select all

procedure TMyChart.ResizeMultipleCircledSeries;
var
  i, TempSize : integer;
begin
  if (SeriesList.Count > 1) then
  begin
    for i := 0 to (SeriesList.Count - 1) do
    begin
      if (Series[i] is TCircledSeries) then
      begin
        with (Series[i] as TCircledSeries) do
        begin
          TempSize := (Self.Width div SeriesList.Count) - 30;
          CustomXRadius := TempSize;
          CustomYRadius := CustomXRadius;
        end;
      end;
    end;
  end;
end;
Here is the small view (400 x 140)

Image

Here is the larger view (795 x 138)

Image

If I put the code in the Resize event of the chart, I can't seem to get the calc working correctly. The pies keep growing at a faster rate than the form which cause them to grow outside the margins of the chart.
BTW, new TeeChart v8 VCL already automatically arranges multiple pie series (in multiple rows/cols).
I saw this. Doesn't it automatically make them two deep? I would like to control the number of pies per row.

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

Post by Narcís » Thu Aug 09, 2007 9:58 am

Hi Isaac,

Maybe you could solve this much easily. You could align the chart to the form:

Code: Select all

  Chart1.Align:=alClient;
Or use something like the code below in the form's OnResize event:

Code: Select all

procedure TForm1.FormCreate(Sender: TObject);
begin
  tmpWidth:=Width;
  tmpHeight:=Height;
end;

procedure TForm1.FormResize(Sender: TObject);
begin
  Chart1.Width:=Chart1.Width+(Width-tmpWidth);
  Chart1.Height:=Chart1.Height+(Height-tmpHeight);

  tmpWidth:=Width;
  tmpHeight:=Height;
end;
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

Isaac Alexander
Newbie
Newbie
Posts: 7
Joined: Wed Jul 11, 2007 12:00 am

Post by Isaac Alexander » Thu Aug 09, 2007 3:25 pm

Maybe you could solve this much easily. You could align the chart to the form
I wish it were that simple. I want to show pies in a different orientation than the default which causes me to set the series Rects myself. The chart is aligned to the form/panel. If the panel could not be resized, I would be done. The problem is that with the resizing. I can't get it to scale properly. The pies grow faster than the form/panel. Please see my earlier comments. Thanks.

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

Post by Narcís » Tue Aug 14, 2007 1:38 pm

Hi Isaac,

Using what Marjan suggested and aligning the chart to alClient automatically resizes the pies when re-dimensioning the form. Have you tried using something like this?

Code: Select all

procedure TForm1.FormCreate(Sender: TObject);
begin
  Chart1.Align:=alClient;

  Series1.MultiPie:=mpDisabled;
  Series2.MultiPie:=mpDisabled;
  Series3.MultiPie:=mpDisabled;

  Series1.Circled:=true;
  Series2.Circled:=true;
  Series3.Circled:=true;

  Series1.FillSampleValues();
  Series2.FillSampleValues();
  Series3.FillSampleValues();
end;

procedure TForm1.Series1BeforeDrawValues(Sender: TObject);
begin
  Chart1.ChartRect:=Rect(10,10,Chart1.Width div 3, Chart1.Height);
end;

procedure TForm1.Series2BeforeDrawValues(Sender: TObject);
begin
  Chart1.ChartRect:=Rect(Chart1.Width div 3,10, (Chart1.Width div 3)*2, Chart1.Height);
end;

procedure TForm1.Series3BeforeDrawValues(Sender: TObject);
begin
  Chart1.ChartRect:=Rect((Chart1.Width div 3)*2, 10, Chart1.Width, Chart1.Height);
end;
If the problem persists, could you please send us a simple example project we can run "as-is" to reproduce the problem here?

You can either post your files at news://www.steema.net/steema.public.attachments or at our upload page.

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

Post Reply