Page 1 of 1

Getting a summary for Data Table

Posted: Thu Jan 03, 2008 10:37 am
by 10547510
Hi!
I have a Chart with Bars and are showing the Data Table, is it possible to get the sum of a column?
Have a look here:
[img]http:\\www.mgm-net.com\teechart\clip2.png[/img]

Thanks
Günter

Posted: Thu Jan 03, 2008 10:55 am
by narcis
Hi Günter,

The easiest way to achieve what you request is using a TAddTeeFunction which would do the sum for you and add the results at the TDataTableTool.

For further information about TeeChart functions please read Tutorial 7 - Working with Functions. Tutorials can be found at TeeChart's program group.

If you don't want to see the add function series in the chart but you want it visible in the TDataTableTool you can set its series colour to transparent:

Code: Select all

  Series4.Color:=clNone;
  Series4.Title:='Sum';
  Series4.ShowInLegend:=false;
As shown in the code snippet above you can also customize series's title and if they appear in the legend.

Posted: Thu Jan 03, 2008 11:24 am
by narcis
Hi Günter,

As an update to my previous reply, I've noticed that setting Series.Color to clNone caused sum not being displayed in the datatable either. An alternative is using this:

Code: Select all

  Series4.LinePen.Visible:=false;
  Series4.Brush.Style:=bsClear;

Posted: Thu Jan 03, 2008 12:07 pm
by 10547510
Hi!
narcis wrote: As an update to my previous reply, I've noticed that setting Series.Color to clNone caused sum not being displayed in the datatable either. An alternative is using this:
Thank you. I have never worked with this 'Functions', so I have to look at the helpfile and tutorials to know where to begin.

Posted: Thu Jan 03, 2008 4:16 pm
by 10547510
narcis wrote:The easiest way to achieve what you request is using a TAddTeeFunction which would do the sum for you and add the results at the TDataTableTool.

For further information about TeeChart functions please read Tutorial 7 - Working with Functions. Tutorials can be found at TeeChart's program group.
I looked at this tutorial and I tried a lot, but I still not able to make this work, maybe you have a small example for something like this?

Thats now the way I try it, but the 'summary' doesn't really work

Code: Select all

  procedure SetzDatenLautKennezeichen(cKZ, cGfTyp  : String; Value : Double);
  var
   oBar : TBarSeries;
   nNr : Integer;
   i : integer;
  begin
   if cKz = '_' then oBar := Series7
   else if cKz = 'T' then oBar := Series8
   else if cKZ = 'E' then oBar := Series9
   else oBar := nil;

   if cGfTyp = 'AN' then nNr := 0
   else if cGfTyp ='AB' then nNr := 1
   else if cGfTyp = 'LI' then nNr := 2
   else if cGfTyp = 'RE' then nNr := 3
   else nNr := 99;
   if (nNr  >90) or (oBar=nil) or (cGfTyp='') then exit;
   case nNR of
   0: nAnSumme := nAnSumme + Value;
   1: nABSumme := nAbSumme + Value;
   2: nLiSumme := nLiSumme + Value;
   3: nReSumme := nReSumme + Value;
   end;
   i := oBar.Labels.IndexOfLabel(cGfTyp);
   if i < 0
    then oBar.AddXy(nNr, Value, cGftyp)
    else oBar.VAluesList[1].Items[i] := oBar.VAluesList[1].Items[i] + Value;
  end;
and at the end of the loop I make a

Code: Select all

  Series10.AddXY(0, nANSumme, 'AN');
  Series10.AddXY(0, nABSumme, 'AB');
  Series10.AddXY(0, nLISumme, 'LI');
  Series10.AddXY(0, nRESumme, 'RE');
So this should be the summary but without success :(

Maybe you can help - Thank you.

Posted: Fri Jan 04, 2008 8:24 am
by narcis
Hi Günter,

Using the code in the functions tutorial you can do something like this:

Code: Select all

uses Series, TeeFunci, TeeDataTableTool;

procedure TForm1.FormCreate(Sender: TObject);
var tmpBarSeries1, tmpBarSeries2, tmpBarSeries3: TBarSeries;
    tmpLineSeries: TLineSeries;
begin
  With Chart1 do
  begin
    //Add data Series
    tmpBarSeries1:=TBarSeries.Create(self);
    tmpBarSeries2:=TBarSeries.Create(self);
    tmpBarSeries3:=TBarSeries.Create(self);
    AddSeries(tmpBarSeries1);
    AddSeries(tmpBarSeries2);
    AddSeries(tmpBarSeries3);

    tmpBarSeries1.MultiBar:=mbStacked;
    tmpBarSeries2.MultiBar:=mbStacked;
    tmpBarSeries3.MultiBar:=mbStacked;

    tmpBarSeries1.Marks.Visible:=false;
    tmpBarSeries2.Marks.Visible:=false;
    tmpBarSeries3.Marks.Visible:=false;

    //Populate them with data (here random)
    tmpBarSeries1.FillSampleValues(10);
    tmpBarSeries2.FillSampleValues(10);
    tmpBarSeries3.FillSampleValues(10);

    //Add a series to be used for an Add Function
    tmpLineSeries:=TLineSeries.Create(self);
    AddSeries(tmpLineSeries);

    //Define the Function Type for the new Series
    tmpLineSeries.SetFunction(TAddTeeFunction.Create(self));

    //Define the Datasource for the new Function Series
    //Datasource accepts the Series titles of the other 2 Series
    tmpLineSeries.DataSources.Clear;
    tmpLineSeries.DataSources.Add( tmpBarSeries1 );
    tmpLineSeries.DataSources.Add( tmpBarSeries2 );
    tmpLineSeries.DataSources.Add( tmpBarSeries3 );

    //    *Note - When populating your input Series manually you will need to
    //    use the Checkdatasource method
    //    - See the section entitled 'Defining a Datasource'
    // Change the Period of the Function so that it groups averages
    // every 2 Points

    //tmpLineSeries.FunctionType.Period := 2;

    Tools.Add(TDataTableTool.Create(self));

    tmpLineSeries.LinePen.Visible:=false;
    tmpLineSeries.Brush.Style:=bsClear;
    tmpLineSeries.Title:='Sum';
    tmpLineSeries.ShowInLegend:=false;
  End;

end;

Posted: Fri Jan 04, 2008 10:32 am
by 10547510
narcis wrote: Using the code in the functions tutorial you can do something like this:

Code: Select all

[/quote]

Thank you. Now It works perfect. I modified the TTeeDataTabletool so every String with beginning '=' is painted bold.