TeeChart Example?

edited November 2007 in FastReport 4.0
Hi,

I have filled a db table with some demo data:

<!--fonto:Lucida Console--><span style="font-family:Lucida Console"><!--/fonto-->CARS PHONES MONITORS LAMPS
44 852 834 973
843 962 600 351
958 650 998 541
<!--fontc--></span><!--/fontc-->

Now I would like to get a chart in FastReport with those 3 series.
I don't get it, folks... how can I do this using the TfrxChart wrapper?
I would like to do a "radar series" and I am using TeeChart PRO 8, but this
is probably unimportant..

Do I need to add series by script?

Any hint is very welcome, thanks a lot
Daniel

Comments

  • edited 5:23PM
    Ok, I have found out the following:

    * FastReport expects one db-rowset per teechart-series
    * for radar series FastReport expects a "LABEL / ANGLE / VALUE" rowformat

    Consequences:
    * I need one query per series
    * if I want to use radar series, I need to change the sql from
    SELECT *
      FROM teechartdata
     WHERE teechartdata_id = 10
    

    to
    SELECT   *
        FROM (SELECT 'Cars' label, 0 angle, cars VALUE
                FROM teechartdata
               WHERE teechartdata_id = 10
              UNION
              SELECT 'Phones' label, 72 angle, phones VALUE
                FROM teechartdata
               WHERE teechartdata_id = 10
              UNION
              SELECT 'Tables' label, 144 angle, TABLES VALUE
                FROM teechartdata
               WHERE teechartdata_id = 10
              UNION
              SELECT 'Monitors' label, 216 angle, monitors VALUE
                FROM teechartdata
               WHERE teechartdata_id = 10
              UNION
              SELECT 'Lamps' label, 288 angle, lamps VALUE
                FROM teechartdata
               WHERE teechartdata_id = 10)
    ORDER BY angle
    

    ... which is of course very bad SQL-coding (too complicated, too many queries).

    How can I simplify this? Read the data from the simple "SELECT *" query and add the series-data
    by script?

    Please help!

    Daniel
  • gordkgordk St.Catherines On. Canada.
    edited 5:23PM
    create the series in the chart editor
    then in the onbeforeprintmethod of the chart object.
    use the add method to add values to each series.
    tip you can connect the query to a hiddendataband set to 1 record
    then in the obpevent of the chart object write code to iterate through the dataset and add the values to the series'.
    begin
    masterdata1.dataset.first;
    for i = 0 to masterdata1.dataset.recordcount-1 do
    begin
    code to add values to series[0];
    code to add values to series[1];
    code to add values to series[2];
    masterdata1.dataset.next;
    next;
    end;
    see the usermanual on working with charts.
  • edited 5:23PM
    Excellent, thanks for pointing the directions, Gord!

    works fine, here's my scripting code (in case somebody's interested... :-) ):
    procedure BuildRadarSeries(series: TfrxSeriesItem);
    var
      j: integer;
      nAngle: integer;                                     
      strSep: string;
      qry: TfrxODACQuery;
      strFieldName: string;                                               
    begin
      strSep := '';
      qry := TfrxODACQuery(invisibleBand.Dataset);                               
      if qry.FieldsCount > 0 then
        nAngle := 360 div qry.FieldsCount
      else
        nAngle := 0;                                                 
      for j := 0 to qry.FieldsCount -1 do
      begin
        strFieldName := qry.Fields[j].FieldName;
        { Source1: "LABEL"}                                                           
        series.Source1 := series.Source1 + strSep + strFieldName;                                                                                                                                                           
        { Source2: "ANGLE"}                                                           
        series.Source2 := series.Source2 + strSep + IntToStr(j * nAngle);
        { Source3: "VALUE"}                                                           
        series.Source3 := series.Source3 + strSep + IntToStr(qry.Value[strFieldName]);                                                                                                                                                           
        strSep := ';';                                        
      end;                  
    end;
    
    
    procedure Chart1OnBeforePrint(Sender: TfrxComponent);
    var
      i: integer;                                
    begin
      i := 0;                             
      with invisibleBand.Dataset do
      begin                    
        First;
        while not eof do
        begin
          BuildRadarSeries(Chart1.SeriesData[i]);                                                                         
          Inc(i);                      
          Next;
        end;  
      end;              
    end;
    
    begin
    
    end.
    

    Cheers, Daniel

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.