I have data of several periods (months). When selecting a period, several Pie-charts will be shown. On that form a user can click to select the next or previous period and the charts are redrawn reflecting the data of that period. So far so good.
PieCharts may contain max 7 pies (user request). If there are more than 7 values (I am not using the OtherPie-functionality) then a 'Other'-pie is created and when you click on that 'other'-pie, a Bar-chart becomes visible. The values of that Bar-series are added to the pie-chart's legend. Works fine.
Now I select period october, click on the other-pie, the bar-graph becomes visible. I select the next period, click on other-pie and the bar-graph again becomes visible. But then I go back to the previous period, click on the other-pie and the bar-graph becomes visible, but much smaller !! Too small ! Selecting the next perioda again, bar-chart is fine, going back, bar-chart is small.
Please look at a screenrecording of the issue : TChart Issue.wmv
Strange to me is that the first time I show the bar-chart of period october, it is going fine, but the second time it is shown in that small format. It seems to me that there has been a property change or something. But then, that might be the wrong thinking direction ...
I looked at the data, tried several properties, currently trying scaling-options. I also asked Steema for help with no results so far.
procedure FillChart(AChart: TChart; AOverviewItemList: TOverviewItemList; APieSeries: TPieSeries; ABarSeries: TBarSeries);
var
i: integer;
vOVitem: TOverviewItem;
LValue: double;
LOtherValue: double;
LUseOtherPieIdx: integer;
LLabel: string;
t: integer;
begin
LSortedGraphItems.Clear;
{ because my users don't want to use the standard functionality of the }
{ 'other'-slices, I first add the items to a stringlist, sort that list }
{ so I can then use the first 6 values for the pie, and if there are more }
{ values I create an 'other'-pie myself and put the values in a bar-series }
{ here the stringlist will be filled }
for vOVItem in AOverviewItemList do
begin
LValue := vOVItem.Details[0].Periods[APeriod].Total;
LLabel := vOVItem.ResultItem.Description;
if abs(LValue) > 0 then
begin
LSortedGraphItems.Add(Format('%10.5f=%s',[LValue, LLabel]));
end;
end;
{ determine when to use values for otherpie, There should never be }
{ more than 7 pies in the pie-chart. }
LUseOtherPieIdx := max(0, LSortedGraphItems.Count - 7);
LSortedGraphItems.Sort;
{ always start clean }
LOtherValue := 0;
ABarSeries.Clear;
{ add values to either the pie- or the bar-series }
for i := 0 to LSortedGraphItems.Count-1 do
begin
lValue := StrToFloatDef(LSortedGraphItems.Names[i], 0);
LLabel := LSortedGraphItems.ValueFromIndex[i];
if LValue < 0 then
begin
LValue := abs(LValue);
LLabel := '-'+LLabel;
end;
if (LUseOtherPieIdx > 0) and (i <= LUseOtherPieIdx) then
begin
LOtherValue := LOtherValue + LValue;
ABarSeries.Add(LValue, LLabel);
end else
begin
APieSeries.Add(LValue, LLabel);
APieSeries.Tag := 0;
end;
end;
{ add a 'other'-pie if necessary }
if (LOtherValue > 0)then
begin
APieSeries.Add(LOtherValue, Translate('Other'));
APieSeries.Tag := 1;
end;
end;
A colleague of mine came with the following solution. After adding the values of the BarSeries add
AChart.LeftAxis.Maximum := ABarSeries.MaxYValue;
An, or the, explanation is that the first time the properties of the LeftAxis are fine, but are overwritten by the values of november. And going back to october with the LeftAxis properties set to fit the values for november, makes the october-bar looking too small.