I have a chart with 2 series, the first representing the total of sells, and the second representing the total of returns, grouped by product. In the second serie, I would like to show in the marks the percent of the returns based on the total of sells, ie:
Product group A
Total sells = 120
Returns = 10
The mark should display 8.33% (since 10 returns represents 8.33% of 100 sells).
Is that possible?
Carlos
Display mark percent relative to other series total
-
- Newbie
- Posts: 33
- Joined: Thu Mar 18, 2004 5:00 am
- Location: Brasil
- Contact:
Re: Display mark percent relative to other series total
Hello Carlos,
You can calculate the value of the label to show in second series as you add values on it. Ie:
You can also calculate the values for the labels later. Ie:
Finally, you can also use the second series' OnGetMarkText event to calculate the labels there:
You can calculate the value of the label to show in second series as you add values on it. Ie:
Code: Select all
uses Series;
procedure TForm1.FormCreate(Sender: TObject);
begin
Chart1.AddSeries(TBarSeries).Marks.Visible:=false;;
Chart1.AddSeries(TBarSeries);
Chart1[0].Add(120);
Chart1[1].Add(10, FormatFloat('#0.##', 10*100/Chart1[0].YValue[0]) + '%');
//By default the axes LabelStyle is set to talAuto and it will show the labels if any series has.
Chart1.Axes.Bottom.LabelStyle:=talValue;
end;
Code: Select all
uses Series, math;
procedure TForm1.FormCreate(Sender: TObject);
var i: Integer;
begin
Chart1.AddSeries(TBarSeries).Marks.Visible:=false;;
Chart1.AddSeries(TBarSeries);
Chart1[0].Add(120);
Chart1[1].Add(10);
for i:=0 to min(Chart1[0].Count-1, Chart1[1].Count-1) do
Chart1[1].Labels[i]:=FormatFloat('#0.##', Chart1[1].YValue[i]*100/Chart1[0].YValue[i]) + '%';
Chart1.Axes.Bottom.LabelStyle:=talValue;
end;
Code: Select all
uses Series, math;
procedure TForm1.FormCreate(Sender: TObject);
var i: Integer;
begin
Chart1.AddSeries(TBarSeries).Marks.Visible:=false;;
Chart1.AddSeries(TBarSeries);
Chart1[0].Add(120);
Chart1[1].Add(10);
Chart1[1].OnGetMarkText:=Series2GetMarkText;
Chart1.Axes.Bottom.LabelStyle:=talValue;
end;
procedure TForm1.Series2GetMarkText(Sender:TChartSeries; ValueIndex:Integer; var MarkText:String);
begin
if (Chart1.SeriesCount>1) and (ValueIndex>-1) and (ValueIndex<min(Chart1[0].Count, Chart1[1].Count)) then
MarkText:=FormatFloat('#0.##', Chart1[1].YValue[ValueIndex]*100/Chart1[0].YValue[ValueIndex]) + '%';
end;
Best Regards,
Yeray Alonso Development & Support Steema Software Av. Montilivi 33, 17003 Girona, Catalonia (SP) | |
Please read our Bug Fixing Policy |