home *** CD-ROM | disk | FTP | other *** search
/ Delphi 5 for Professionals / DELPHI5.iso / AddOns / Components / TEECHART / Delphi1_And_Delphi2 / EXAMPLES / EXTENDED / TEEGRID.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1998-10-24  |  4.7 KB  |  172 lines

  1. {*********************************************}
  2. {  TeeChart Grid functions                    }
  3. {  Copyright (c) 1997 by David Berneda        }
  4. {  All rights reserved                        }
  5. {*********************************************}
  6. unit Teegrid;
  7.  
  8. interface
  9.  
  10. Uses Grids,Chart;
  11.  
  12. { This procedure fills the AGrid parameter with the AChart Series
  13.   values and labels. }
  14.  
  15. type ChartGridOptions=(cgLabels,cgColors,cgXValues);
  16.      TChartGridOptions=set of ChartGridOptions;
  17.  
  18.      TTeeGridColumnValues=Record
  19.       ColLabels,
  20.       ColColors,
  21.       ColXValues,
  22.       FirstColSeries:Integer;
  23.      end;
  24.  
  25. Procedure TeeFillGrid( AGrid:TStringGrid;
  26.                        AChart:TCustomChart;
  27.                        Const AOptions:TChartGridOptions;
  28.                        Var ColumnValues:TTeeGridColumnValues);
  29.  
  30. { This procedure modifies a Series point in (ARow,ACol) with "value" }
  31. Procedure TeeModifyGrid( AChart:TCustomChart;
  32.                          ACol,ARow:Longint;
  33.                          Const Value:String;
  34.                          Const ColumnValues:TTeeGridColumnValues );
  35. implementation
  36.  
  37. Uses TeeProcs,Teengine,TeCanvas,SysUtils,Graphics;
  38.  
  39. Procedure TeeFillGrid( AGrid:TStringGrid;
  40.                        AChart:TCustomChart;
  41.                        Const AOptions:TChartGridOptions;
  42.                        Var ColumnValues:TTeeGridColumnValues);
  43.  
  44.   Function GetMaxPoints:Integer;
  45.   var t:Integer;
  46.   begin
  47.     result:=0;
  48.     for t:=0 to AChart.SeriesCount-1 do
  49.       result:=MaxLong(result,AChart[t].Count);
  50.   end;
  51.  
  52. Var ACol,ARow,ColSeries:Integer;
  53.     ASeries:TChartSeries;
  54.     tmp:TChartValueList;
  55.     tmpColumnValues:TTeeGridColumnValues;
  56. begin
  57.   With AGrid do
  58.   begin
  59.     Cells[0,0]:='#';
  60.     ACol:=1;
  61.     With ColumnValues do
  62.     begin
  63.       ColLabels:=-1;
  64.       ColColors:=-1;
  65.       ColXValues:=-1;
  66.       if cgLabels in AOptions then
  67.       begin
  68.         Cells[ACol,0]:='Label';
  69.         ColLabels:=ACol;
  70.         Inc(ACol);
  71.       end;
  72.       if cgColors in AOptions then
  73.       begin
  74.         Cells[ACol,0]:='Color';
  75.         ColColors:=ACol;
  76.         Inc(ACol);
  77.       end;
  78.       if cgXValues in AOptions then
  79.       begin
  80.         Cells[ACol,0]:='X';
  81.         ColXValues:=ACol;
  82.         Inc(ACol);
  83.       end;
  84.       FirstColSeries:=ACol;
  85.     end;
  86.     tmpColumnValues:=ColumnValues;
  87.     ColCount:=ACol+AChart.SeriesCount;
  88.     RowCount:=1+GetMaxPoints;
  89.     for ACol:=0 to AChart.SeriesCount-1 do
  90.     begin
  91.       ASeries:=AChart[ACol];
  92.       ColSeries:=tmpColumnValues.FirstColSeries+ACol;
  93.       Cells[ColSeries,0]:=ASeries.Name;
  94.       for ARow:=1 to ASeries.Count do
  95.       begin
  96.         Cells[0,ARow]:=IntToStr(ARow-1);   { point number }
  97.         With tmpColumnValues do
  98.         begin
  99.           if ColLabels<>-1 then
  100.              Cells[ColLabels,ARow]:=ASeries.XLabel[ARow-1];  { point label }
  101.           if ColColors<>-1 then
  102.              Cells[ColColors,ARow]:=IntToStr(ASeries.ValueColor[ARow-1]);  { point label }
  103.           if ColXValues<>-1 then
  104.           begin
  105.             if ASeries.YMandatory then tmp:=ASeries.XValues
  106.                                   else tmp:=ASeries.YValues;
  107.             Cells[ColXValues,ARow]:=FloatToStr(tmp[ARow-1]);
  108.           end;
  109.         end;
  110.         Cells[ColSeries,ARow]:=FloatToStr(ASeries.MandatoryValueList[ARow-1]);
  111.       end;
  112.       With tmpColumnValues do
  113.       begin
  114.         ColLabels:=-1;
  115.         ColColors:=-1;
  116.         ColXValues:=-1;
  117.       end;
  118.     end;
  119.   end;
  120. end;
  121.  
  122. Procedure TeeModifyGrid( AChart:TCustomChart;
  123.                          ACol,ARow:Longint;
  124.                          Const Value:String;
  125.                          Const ColumnValues:TTeeGridColumnValues );
  126. Var tmpColor:TColor;
  127. begin
  128.   if ARow=0 then exit;
  129.   With ColumnValues do
  130.   if ACol=ColLabels then
  131.   begin
  132.     if AChart.SeriesCount>0 then
  133.        AChart[0].XLabel[ARow-1]:=Value;
  134.   end
  135.   else
  136.   if ACol=ColColors then
  137.   begin
  138.     if AChart.SeriesCount>0 then
  139.     begin
  140.       if Value='' then tmpColor:=clTeeColor
  141.                   else tmpColor:=StrToInt(Value);
  142.       AChart[0].ValueColor[ARow-1]:=tmpColor;
  143.     end;
  144.   end
  145.   else
  146.   if ACol=ColXValues then
  147.   begin
  148.     if AChart.SeriesCount>0 then
  149.       if (Value<>'') and (Value<>'-') then AChart[0].XValue[ARow-1]:=StrToFloat(Value);
  150.   end
  151.   else
  152.   begin
  153.     if AChart.SeriesCount>ACol-FirstColSeries then
  154.     begin
  155.       With AChart[ACol-FirstColSeries] do
  156.       begin
  157.         While Count<ARow do AddNull('');
  158.         if Value='' then ValueColor[ARow-1]:=clNone
  159.         else
  160.         begin
  161.           MandatoryValueList[ARow-1]:=StrToFloat(Value);
  162.           if ValueColor[ARow-1]=clNone then
  163.              ValueColor[ARow-1]:=clTeeColor;
  164.         end;
  165.       end;
  166.     end;
  167.   end;
  168.   AChart.Repaint;
  169. end;
  170.  
  171. end.
  172.