Page 1 of 1

How to display legend with values labels

Posted: Fri May 11, 2007 3:36 am
by 9081616
Hi
I was wondering whether someone can help me with legend problem. I'm using TeeChart V6 and I want to display a pie chart with legend. My data is very simple:

Sales
Q1 100
Q2 120
Q3 150
Q4 180

I want to display this in pie chart and I want my legend to have Q1, Q2, Q3, Q4. However when I go into the "Legend" tab, the choices are :

Automatic
Series Names
Series Values
Last Value

If I pick Series Names, then the legend would displays 'Sales' which is my series name. If I pick Series Values, the legend displays 100, 120 150, 180.

Is there a way I can display the legend as Q1, Q2, Q3, Q4?

This is important for us because our client wants to be able to display their graph this way.

Thanks in advance for you help.
Vickie

Posted: Fri May 11, 2007 9:33 am
by narcis
Hi Vickie,

You can add the text as points labels as shown in the code below. That way legend will automatically display points values and labels. If you want to only display points labels then you could also add OnGetLegendText event as shown in the example.

Code: Select all

procedure TForm1.FormCreate(Sender: TObject);
begin
  With Series1 do
  begin
    AddPie(100,'Q1');
    AddPie(120,'Q2');
    AddPie(150,'Q3');
    AddPie(180,'Q4');
  end;
end;

procedure TForm1.Chart1GetLegendText(Sender: TCustomAxisPanel;
  LegendStyle: TLegendStyle; Index: Integer; var LegendText: String);
begin
  LegendText:=Series1.Labels[Index];
end;