|
Solution:
|
There are several approaches. We'll do it with two THorizBarSeries. Basically, age pyramid is very similar to a horizontal bar series, with the exception each vertical entry must have two values : a "positive" - right value and "negative" - left value. If we try to use two THorizBarSeries, we run into two obstacles :
1. Usually, data for age pyramid is positive. The problem is how to get "negative" values without actually changing the data itself. There are several possibilities but the easiest is using TChartValuesList.Multiplyer property. Setting LeftSeries.XValues.Multiplier:=-1; will solve this problem.
2. If we use negative values (to get the correct appearance for age pyramid), the labels will range from negative to zero to positive values. But we'd like to have labels with positive to zero to positive values. The solution is to use Chart OnGetAxisLabel event and remove all '-' from the label text. This code will work in Delphi 4/5, but something similar can be done in Delphi 3 and
CBuilder.
procedure TForm1.Chart1GetAxisLabel(Sender: TChartAxis;
Series: TChartSeries; ValueIndex: Integer; var LabelText: String);
var tmp : string;
begin
// remove "-" from LabelText
if (Sender=Chart1.BottomAxis) then
begin
tmp:=LabelText;
LabelText:=StringReplace(tmp,'-','',[rfReplaceAll]);
// Delphi 4-5 only
end;
end;
|