Pie Chart Bug

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
Ed
Newbie
Newbie
Posts: 33
Joined: Tue Mar 09, 2004 5:00 am
Location: Oregon, USA
Contact:

Pie Chart Bug

Post by Ed » Mon Mar 22, 2004 6:26 pm

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

Marjan
Site Admin
Site Admin
Posts: 745
Joined: Fri Nov 07, 2003 5:00 am
Location: Slovenia
Contact:

Post by Marjan » Tue Mar 23, 2004 4:44 pm

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.
Marjan Slatinek,
http://www.steema.com

ChrisD
Newbie
Newbie
Posts: 3
Joined: Mon May 31, 2004 4:00 am
Location: Australia
Contact:

Incomplete Pie Chart

Post by ChrisD » Mon Jun 07, 2004 6:07 am

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

Marjan
Site Admin
Site Admin
Posts: 745
Joined: Fri Nov 07, 2003 5:00 am
Location: Slovenia
Contact:

Post by Marjan » Mon Jun 07, 2004 3:19 pm

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;
Marjan Slatinek,
http://www.steema.com

Thomas Klingler
Advanced
Posts: 103
Joined: Tue Mar 02, 2004 5:00 am
Location: Bad Wurzach
Contact:

Post by Thomas Klingler » Tue Jul 19, 2005 3:20 pm

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...

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Wed Jul 20, 2005 7:32 am

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.
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Post Reply