Auto Other Slice
Auto Other Slice
I don't care about displaying an other slice in my pie chart unless it isn't currently being displayed in the legend. Is there some way to have the Other Slice automatically create itself, but only if all categories don't fit in the legend? Thanks.
Re: Auto Other Slice
Hello,
You may have to polish it, but here it is a simple example trying to do it:
You may have to polish it, but here it is a simple example trying to do it:
Code: Select all
uses Math;
type TPieSeriesAccess=class(TPieSeries);
procedure TForm1.Chart1BeforeDrawChart(Sender: TObject);
function SlicesCount: Integer;
var i, nOther: Integer;
begin
nOther:=0;
if Series1.OtherSlice.Style = poBelowValue then
for i:=0 to Series1.Count-1 do
if Series1.YValue[i]<=Series1.OtherSlice.Value then
Inc(nOther);
result:=Series1.Count-nOther;
if nOther>0 then Inc(result);
end;
procedure RecalcOtherSlices;
var i: Integer;
tmp: Double;
begin
if Series1.OtherSlice.Style = poNone then
begin
Series1.OtherSlice.Style:=poBelowValue;
Series1.OtherSlice.Value:=Series1.YValues.MinValue;
end;
tmp:=Series1.YValues.MaxValue;
for i:=0 to Series1.Count-2 do
if Series1.YValue[i] > Series1.OtherSlice.Value then
tmp:=Min(tmp, Series1.YValue[i]);
Series1.OtherSlice.Value:=tmp;
TPieSeriesAccess(Series1).DoBeforeDrawChart;
end;
begin
if (Chart1.Legend.Items.Count > 0) then
begin
if Series1.OtherSlice.Style<>poNone then
Series1.Delete(Series1.Count-1);
Series1.OtherSlice.Style:=poNone;
Chart1.Canvas.AssignFont(Chart1.Legend.Font);
while Chart1.Legend.Top+(SlicesCount*(Chart1.Canvas.FontHeight) + 7)+10 > Chart1.Height do
RecalcOtherSlices;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Series1.FillSampleValues(10);
end;
Best Regards,
Yeray Alonso Development & Support Steema Software Av. Montilivi 33, 17003 Girona, Catalonia (SP) | |
Please read our Bug Fixing Policy |