Page 1 of 1

TeeChart7 PieChart Percent display error

Posted: Tue May 25, 2004 3:22 pm
by 8573867
Hi there,

last week I updated our software package from TeeChart6.X to
TeeChart 7. One PieChart which previously displayed correct percentage values now displays wrong percentage values (always smaller than 100%). If I add up the displayed values they are much smaller than 100% whereas the data/numbers which are given to the chart add exactly up to 100%.

I extracted an example application:

// Begin of form file

object Form1: TForm1
Left = 190
Top = 131
Width = 449
Height = 330
Caption = 'Form1'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
PixelsPerInch = 96
TextHeight = 13
object Button1: TButton
Left = 176
Top = 264
Width = 129
Height = 25
Caption = 'Show percents'
TabOrder = 0
OnClick = Button1Click
end
object QuantChart: TChart
Left = 0
Top = 0
Width = 441
Height = 257
HelpContext = 85260
AllowPanning = pmNone
BackWall.Brush.Color = clWhite
BackWall.Brush.Style = bsClear
BackWall.Pen.Visible = False
Gradient.Visible = True
Legend.ResizeChart = False
Legend.TextStyle = ltsPlain
Legend.Visible = False
Title.AdjustFrame = False
Title.Text.Strings = (
'Rietveld Qunatification Results')
Title.Visible = False
AxisVisible = False
ClipPoints = False
Frame.Visible = False
View3D = False
View3DOptions.Elevation = 315
View3DOptions.Orthogonal = False
View3DOptions.Perspective = 0
View3DOptions.Rotation = 360
View3DOptions.Zoom = 102
View3DWalls = False
Zoom.Allow = False
Align = alTop
BevelOuter = bvLowered
TabOrder = 1
PrintMargins = (
15
43
15
43)
object PieSeries: TPieSeries
Marks.Callout.Brush.Color = clBlack
Marks.Style = smsLabelPercent
Marks.Visible = True
PercentFormat = '##0.# %'
ShowInLegend = False
Circled = True
ExplodeBiggest = 20
Gradient.Direction = gdRadial
OtherSlice.Legend.Visible = False
PieValues.Name = 'Pie'
PieValues.Order = loDescending
end
end
end

// End of form file

// Begin PAS file:

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, TeEngine, Series, ExtCtrls, TeeProcs, Chart;

type
TForm1 = class(TForm)
Button1: TButton;
QuantChart: TChart;
PieSeries: TPieSeries;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
QuantChart.SeriesList.Items[0].Clear;
QuantChart.SeriesList.Items[0].Add(20, 'Test First Red', clRed);
QuantChart.SeriesList.Items[0].Add(40, 'Test Second Green', clGreen);
QuantChart.SeriesList.Items[0].Add(40, 'Test Third Blue', clBlue);
QuantChart.SeriesList.Items[0].Marks.Style := smsPercent;
end;

end.

// End of PAS file

Posted: Tue May 25, 2004 4:21 pm
by Pep
Hi Thomas,

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:

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.