Hi Marjan,
Initially I posted this to steema.public.teechart6.delphi
Here we go again, so I'll get a prompter reply:
Are there any plans to support "stacked 100" as Excel does?
Currently, for TeeChart the stacked 100% represent "relative value of each element of the Series to a total of 100%."... while for Excel the stacked 100% represent the relative value of each element in the group to a total of 100%.
stacked 100
stacked 100
--
Lucian
Lucian
Hi, Lucian.
Yes, I understand now <g>. The problem is in series mark text - you want to display percent value for each group. You're correct, TeeChart calculates percentage differently than Excel. The solution/workaround is to calculate the sum for each group and then in TChartSeries.OnGetMarkText event calculate percentage and finally convert it to string and assign it to OnGetMarkText MarkText parameter. Here is the code I'd use (also see attached application):
Perhaps this is something we could do internally in next TeeChart version
(I'll add it to our wish list).
Yes, I understand now <g>. The problem is in series mark text - you want to display percent value for each group. You're correct, TeeChart calculates percentage differently than Excel. The solution/workaround is to calculate the sum for each group and then in TChartSeries.OnGetMarkText event calculate percentage and finally convert it to string and assign it to OnGetMarkText MarkText parameter. Here is the code I'd use (also see attached application):
Code: Select all
procedure TForm1.FormCreate(Sender: TObject);
begin
Series1.Marks.ArrowLength := - 15;
Series2.Marks.ArrowLength := - 15;
Series3.Marks.ArrowLength := - 15;
Series1.OnGetMarkText := Series1GetMarkText;
Series2.OnGetMarkText := Series1GetMarkText;
Series3.OnGetMarkText := Series1GetMarkText;
Series1.Add(50);
Series1.Add(10);
Series1.Add(15);
Series2.Add(40);
Series2.Add(30);
Series2.Add(15);
Series3.Add(10);
Series3.Add(60);
Series3.Add(60);
end;
procedure TForm1.Series1GetMarkText(Sender: TChartSeries;
ValueIndex: Integer; var MarkText: String);
var i: Integer;
Sum,Pct : Double;
begin
// Step 1 : get the sum of a group
Sum := 0.0;
for i := 0 to Sender.ParentChart.SeriesList.Count -1 do
Sum := Sum + Sender.ParentChart.Series[i].YValue[ValueIndex];
// Step 2 : calculate pecentage
if Sum <> 0.0 then
begin
Pct := 100.0*Sender.YValue[ValueIndex]/Sum;
MarkText := FormatFloat('0.00%',Pct);
end;
end;
(I'll add it to our wish list).
Marjan Slatinek,
http://www.steema.com
http://www.steema.com