Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8070257
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T13:21:46+00:00 2026-06-05T13:21:46+00:00

I am porting a home-brew report Delphi reporting solution into FastReport and I’ve come

  • 0

I am porting a home-brew report Delphi reporting solution into FastReport and I’ve come to the need for a chart showing the distribution of a field in a dataset (A ‘Bell curve’ or normal distribution). Previously I wrote code to sort field values into cells (eg 100 say) and then plotted a TChart histogram of cell counts (Y) against 1-100 (X). FastReport has good integration with TChart and I am plotting lines of field values easily. Is there an existing means of plotting a distribution chart or should I create a new data set of sorted cells and plot that?
Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T13:21:47+00:00Added an answer on June 5, 2026 at 1:21 pm

    When I realised that there was no direct solution to this, I created a class which others might find useful. It takes a data set and does all the hard work of building a list of frequency cells for a specific field name and then cacheing this to allow a ‘GetValue’ call from a TfrxUserDataSet called ‘Distributions’. The report user can then simply drop a bar chart in the report, nominate ‘Distributions’ as the data set and choose the required field for ‘Y values’. ‘X values’ must be set to the same field name but with ‘-X’ appended – my class then transparently returns X and Y values for the chart having built the frequency cells on the first call. No FastReport code is involved.

    Although working, this is fledgling code and could be improved further, for example at present the X values span min to max. A better display would be to use 3 or 6-sigma (standard deviation) but this is easy to modify.

    unit UartFastReportsDistribution;
    interface
    
    uses
      DB,
      Classes;
    
    const
      CellCount = 101;
    
    type
      TCellArray = array[0..CellCount-1] of integer;
      TXValues   = array[0..CellCount-1] of double;
    
      TDistributionCells = class( TObject )
        constructor Create( ADataSet : TDataSet; const AFieldName : string );
      PRIVATE
        FDataSet : TDataSet;
        FFieldName : string;
        FCells : TCellArray;
        FLastRecNo : integer;
        FCellsMax : integer;
        FDataMin, FDataMax : double;
        procedure BuildCells;
        function  XValue( AIndex : integer ) : double;
        function  YValue( AIndex : integer ) : double;
        function  DataMean : double;
        function  DataDevPk : double;
      end;
    
    
      TArtFastReportsDistribution = class( TObject )
        constructor Create( ADataSet : TDataSet );
        destructor Destroy; override;
      private
        FDataSet : TDataSet;
        FDistributions : TStringList;
    
        function  NameToDistribution( const AFieldName: string) : TDistributionCells;
      PUBLIC
        procedure DoGetData( const AFieldName: string; ARecNo : integer; var Value: Variant);
        function  RecordCount : integer;
      end;
    
    implementation
    
    uses
      Math,
      SysUtils;
    
    { TArtFastReportsDistribution }
    
    function TArtFastReportsDistribution.NameToDistribution( const AFieldName: string) : TDistributionCells;
    var
      I : integer;
    begin
      I := FDistributions.IndexOf( AFieldName );
      if I = -1 then
        begin
        Result := TDistributionCells.Create( FDataSet, AFieldName );
        FDistributions.AddObject( AfieldName, Result );
        end
       else
        Result := FDistributions.Objects[I] as TDistributionCells;
    end;
    
    
    constructor TArtFastReportsDistribution.Create(ADataSet: TDataSet);
    begin
      inherited Create;
      FDataSet := ADataSet;
      FDistributions := TStringList.Create;
      FDistributions.OwnsObjects := True;
    end;
    
    destructor TArtFastReportsDistribution.Destroy;
    begin
      FreeAndNil( FDistributions );
      inherited;
    end;
    
    procedure TArtFastReportsDistribution.DoGetData(const AFieldName: string;
      ARecNo : integer; var Value: Variant);
    
    var
      sFieldName : string;
      bIsXValue  : boolean;
      I          : integer;
      Dist       : TDistributionCells;
    begin
      sFieldName := AFieldName;
      I := Pos( '-X', sFieldName );
      bIsXValue := I > 0;
      if bIsXValue then
        Delete( sFieldName, I, MaxInt );
    
      Dist := NameToDistribution( sFieldName );
    
      If (ARecNo = 1) and (Dist.FLastRecNo <> 1) then
        Dist.BuildCells;
    
      Dist.FLastRecNo := ARecNo;
    
      if bIsXValue then
        Value := Dist.XValue(ARecNo-1)
       else
        Value := Dist.YValue(ARecNo-1);
    end;
    
    
    function TArtFastReportsDistribution.RecordCount: integer;
    begin
      Result := CellCount;
    end;
    
    { TDistributionCells }
    
    
    { TDistributionCells }
    
    procedure TDistributionCells.BuildCells;
    
      procedure ClearCells;
      var
        I : integer;
      begin
        for I := 0 to CellCount-1 do
          FCells[I] := 0;
    
        FCellsMax := 0;
        FDataMin := 0.0;
        FDataMax := 0.0;
      end;
    
    
      function GetDataSetFieldValues : TFloatArray;
      var
        I : integer;
        Field : TField;
      begin
        Field := FDataSet.FieldByName( FFieldName );
        if not Assigned( Field ) then
          Raise Exception.CreateFmt( 'Missing distribution field "%s"', [FFieldName] );
    
        SetLength( Result, FDataSet.RecordCount );
        FDataSet.First;
        I := 0;
        While not FDataset.EOF do
          begin
          Result[I] := Field.AsFloat;
          Inc(I);
          FDataSet.Next;
          end;
      end;
    
    
    var
      I,
      iCellCount,
      iOffset : integer;
      F : double;
      Data : TFloatArray;
    begin
      ClearCells;
    
      If FDataSet.RecordCount = 0 then
        Exit;
    
      Data := GetDataSetFieldValues;
    
      FDataMin  := MinValue( Data );
      FDataMax  := MaxValue( Data );
    
      FCellsMax := 0;
      iCellCount   := Length( FCells );
    
      for I := 0 to Length( Data )-1 do
        begin
        F := Data[I];
    
        F := (F - DataMean + DataDevPk)/(2*DataDevPk);
        iOffset := Trunc( iCellCount * F );
        If iOffset < 0 then
          iOffset := 0
         else
          If iOffset > iCellCount-1 then
           iOffset := CellCount-1;
        FCells[iOffset] := FCells[iOffset] + 1;
    
        If I = 0 then
          FCellsMax := FCells[iOffset]
         else
          FCellsMax := Max( FCells[iOffset], FCellsMax );
        end;
    
    end;
    
    
    constructor TDistributionCells.Create(ADataSet: TDataSet;
      const AFieldName: string);
    begin
      inherited Create;
      FDataSet := ADataSet;
      FFieldName := AFieldName;
    end;
    
    function TDistributionCells.DataDevPk: double;
    begin
      Result := FDataMax - DataMean;
    end;
    
    function TDistributionCells.DataMean: double;
    begin
      Result := (FDataMin + FDataMax) / 2;
    end;
    
    function TDistributionCells.XValue(AIndex: integer): double;
    begin
      Result := AIndex;
      Result := (Result / CellCount) - 0.5;               
      Result := DataMean + (Result*2*DataDevPk);
    end;
    
    function TDistributionCells.YValue(AIndex: integer): double;
    begin
    //  Result := 100.0 * FCells[AIndex] / FCellsMax;
      Result := FCells[AIndex];
    end;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am porting a Windows application to OSX and need to get user's home,
I am currently porting an application from iOS into Android and I have ran
My goal is to VPN from my iPhone into my home network for iTunes
Below am posting my jsp page. home.jsp <%@taglib uri=/WEB-INF/struts-bean.tld prefix=bean%> <%@taglib uri=/WEB-INF/struts-html.tld prefix=html %>
Porting an application from C# (1.1 framework) to VB.NET (3.5 framework), and I have
Porting code from 32bit to 64bit. Lots of places with int len = strlen(pstr);
I'm porting some WPF code to WinRT. The code uses System.Windows.Media.Animation.ParallelTimeline to syncrhonize two
We're porting a legacy Java app to JRuby and would like to reuse some
I'm porting an existing app to rails that makes extensive use of stylized anchors
I'm porting the T6963-based LCD driver from AVR-GCC to the microchip C18 compiler. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.