Page 1 of 1
Pie Chart Bug
Posted: Mon Mar 22, 2004 6:26 pm
by 9336214
Show stopper here.
Drop a TChart on a form and add a pie series to it. Make it so that the
marks show the percent value. Then add a value to it in code, such as:
constructor TForm1.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
Series1.Clear;
Series1.Add(100, 'Item #1');
end; // Create
Run it. At least in my copy for the above example it says 'Item #1' is 50%.
--and there is only one pie in the chart. (Different results occur when different number of items are added).
Please let me know how to fix this.
Thanks
Ed Dressel
Posted: Tue Mar 23, 2004 4:44 pm
by Marjan
Hi, Ed.
Actually, the problem happens with all series. The TotalABS value, used in all series to calculate the percentage is not calculated correctly. The lower limit in the for loop (the TChartValueList.RecalcStats routine) is set to StartIndex. The correct limit should be set at StartIndex+1. Here is the corrected code - the relevant part (will be included in next TeeChart maintenance release):
Code: Select all
if Count>0 then
begin
if StartIndex=0 then
begin
tmpValue:=Value[0];
FMinValue:=tmpValue;
FMaxValue:=tmpValue;
FTotal:=tmpValue;
FTotalABS:=Abs(tmpValue);
end;
for t:=StartIndex+1 to Count-1 do // MS : 7.01 fix
Begin
tmpValue:=Value[t];
if tmpValue<FMinValue then FMinValue:=tmpValue else
if tmpValue>FMaxValue then FMaxValue:=tmpValue;
FTotal:=FTotal+tmpValue;
FTotalABS:=FTotalABS+Abs(tmpValue);
end;
end;
If you don't have TC source code, then the only solution (for the time being) I can think of is to use the OnGetMarkText eventt to manually recalculate total abs and the percentage for each point.
Incomplete Pie Chart
Posted: Mon Jun 07, 2004 6:07 am
by 9232655
All my Pie Charts are incomplete, always a slice missing. I assume this problem is related to the problem you describe.
I do not have source code and consider this to be a very serious problem. When is the ETA for the next maintance release?
The quicky solution I am testing at the moment is to do
series->Add(0, "");
before I start adding the real Points.
I could not work out how to do your "OnGetMarkText event" solution.
Could you elaborate?
Thanks
Chris Durkin
Posted: Mon Jun 07, 2004 3:19 pm
by Marjan
Hi, Chris.
When is the ETA for the next maintance release
A fair estimate puts the release date within next month.
Could you elaborate?
Sure, no problem. Basically, you can use the OnGetMarkText event to calculate each slice percentage (by dividing 100 * current value with calculated sum and then transforming it to string). Something along these lines:
Code: Select all
procedure TForm1.Series1GetMarkText(Sender: TChartSeries;
ValueIndex: Integer; var MarkText: String);
var sum, pct: double;
i: integer;
begin
// step 1 : calculate correct sum
sum := 0.0;
for i := 0 to Sender.Count - 1 do sum := sum + Abs(Sender.YValue[i]);
// step 2 : calc percentage
pct := 100*Sender.YValue[ValueIndex]/sum;
// step 3 : transform to string
MarkText := FormatFloat('0.00 %',pct);
end;
Posted: Tue Jul 19, 2005 3:20 pm
by 8443014
We are experiencing the same problem...incorrect marktext on a pie chart. We have release 7, but how do we tell if we have the maintenance release with this fix? The About dialog does not provide complete version information...
Posted: Wed Jul 20, 2005 7:32 am
by narcis
Hi ungos,
As Marjan's message was posted on 7th June 2004 I'd say that at least from v7.02 this fix is inlcuded and I'm not sure if it already was in v7.01. However current TeeChart version is v7.04. Right-clicking on a TChart in a form and selecting about should give you the exact version number.
If you don't have the latest version available you can download it from our customer download area.