Difference between revisions of "TsWorksheetChartSource/fr"

From Lazarus wiki
Jump to navigationJump to search
(New page: TsWorksheetChartSource is a charting component which is available in the source code of the FPSpreadsheet library. It is a chart data source component designed to work...)
 
m (Fixed syntax highlighting)
 
(4 intermediate revisions by 2 users not shown)
Line 1: Line 1:
TsWorksheetChartSource is a charting component which is available in the source code of the [[FPSpreadsheet/fr|FPSpreadsheet]] library. It is a chart data source component designed to work with the TChart component from the [[TAChart|TAChartLazarusPkg package]], which usually comes pre-installed with Lazarus.
+
{{TsWorksheetChartSource}}
  
==Usage==
+
TsWorksheetChartSource est un composant graphique qui est disponible dans le code source de la bibliothèque [[FPSpreadsheet/fr|FPSpreadsheet]]. Il s'agit d'un composant de source de données pour graphique conçu pour fonctionner avec le composant TChart provenant du [[TAChart/fr|paquet TAChartLazarusPkg.]], lequel est généralement pré-installé avec Lazarus.
  
At the moment TsWorksheetChartSource has the following properties to control it's behavior:
+
== Utilisation==
  
<delphi>
+
Pour le moment TsWorksheetChartSource a les propriétés suivantes pour contrôler son comportement:
 +
 
 +
<syntaxhighlight lang=pascal>
 
   published
 
   published
 
     property PointsNumber: Integer read FPointsNumber write SetPointsNumber default 0;
 
     property PointsNumber: Integer read FPointsNumber write SetPointsNumber default 0;
Line 15: Line 17:
 
     property YSelectionDirection: TsSelectionDirection read FYSelectionDirection write SetYSelectionDirection;
 
     property YSelectionDirection: TsSelectionDirection read FYSelectionDirection write SetYSelectionDirection;
 
   end;
 
   end;
</delphi>
+
</syntaxhighlight>
  
 
The Chart will display an amount of PointsNumber points, being that on the coordinates of the X-Axis will be collected from the worksheet starting in the position (XFirstCellRow, XFirstCellCol). Subsequent X-Axis values will be taken from the cells directly to the right of the first cell, if XSelectionDirection has value fpsHorizontalSelection, or bellow the first cell, if XSelectionDirection has value fpsVerticalSelection. The values will be taken in sequence so if another layout of the data exists, such as each second cell or going up, it can be created by copying the relevant data to a new TsWorksheet.
 
The Chart will display an amount of PointsNumber points, being that on the coordinates of the X-Axis will be collected from the worksheet starting in the position (XFirstCellRow, XFirstCellCol). Subsequent X-Axis values will be taken from the cells directly to the right of the first cell, if XSelectionDirection has value fpsHorizontalSelection, or bellow the first cell, if XSelectionDirection has value fpsVerticalSelection. The values will be taken in sequence so if another layout of the data exists, such as each second cell or going up, it can be created by copying the relevant data to a new TsWorksheet.
Line 34: Line 36:
 
To load the data from the grid and into the chart a button was created with the following code. Notice that we can't just use any Grid, it has to be a FPSpreadsheet Grid, which has the class TsWorksheetGrid:
 
To load the data from the grid and into the chart a button was created with the following code. Notice that we can't just use any Grid, it has to be a FPSpreadsheet Grid, which has the class TsWorksheetGrid:
  
<delphi>
+
<syntaxhighlight lang=pascal>
 
type
 
type
 
    
 
    
Line 58: Line 60:
 
   FPSChartSource.LoadFromWorksheetGrid(WorksheetGrid);
 
   FPSChartSource.LoadFromWorksheetGrid(WorksheetGrid);
 
end;
 
end;
</delphi>
+
</syntaxhighlight>
  
 
And finally we can see how this works nicely in a running application in the picture bellow:
 
And finally we can see how this works nicely in a running application in the picture bellow:
  
 
[[Image:Fpschart_run.png]]
 
[[Image:Fpschart_run.png]]

Latest revision as of 01:48, 2 March 2020

English (en) français (fr)

TsWorksheetChartSource est un composant graphique qui est disponible dans le code source de la bibliothèque FPSpreadsheet. Il s'agit d'un composant de source de données pour graphique conçu pour fonctionner avec le composant TChart provenant du paquet TAChartLazarusPkg., lequel est généralement pré-installé avec Lazarus.

Utilisation

Pour le moment TsWorksheetChartSource a les propriétés suivantes pour contrôler son comportement:

  published
    property PointsNumber: Integer read FPointsNumber write SetPointsNumber default 0;
    property XFirstCellCol: Integer read FXFirstCellCol write SetXFirstCellCol default 0;
    property XFirstCellRow: Integer read FXFirstCellRow write SetXFirstCellRow default 0;
    property YFirstCellCol: Integer read FYFirstCellCol write SetYFirstCellCol default 0;
    property YFirstCellRow: Integer read FYFirstCellRow write SetYFirstCellRow default 0;
    property XSelectionDirection: TsSelectionDirection read FXSelectionDirection write SetXSelectionDirection;
    property YSelectionDirection: TsSelectionDirection read FYSelectionDirection write SetYSelectionDirection;
  end;

The Chart will display an amount of PointsNumber points, being that on the coordinates of the X-Axis will be collected from the worksheet starting in the position (XFirstCellRow, XFirstCellCol). Subsequent X-Axis values will be taken from the cells directly to the right of the first cell, if XSelectionDirection has value fpsHorizontalSelection, or bellow the first cell, if XSelectionDirection has value fpsVerticalSelection. The values will be taken in sequence so if another layout of the data exists, such as each second cell or going up, it can be created by copying the relevant data to a new TsWorksheet.

The same is valid for the Y-Axis value, but applies to the properties YFirstCellCol, YFirstCellRow and YSelectionDirection. The property PointsNumber is valid for both axis.

Be careful that if a value could not be read from the worksheet it's value will be considered zero.

The values for Worksheet coordinates use the same values as the FPSpreadsheet API, that is, they are zero-based. So, for example, to select the cell B2 as the starting position for X-Axis values the following values should be used: XFirstCellCol = 1 and XFirstCellRow = 1

Example

A simple example is present in the fpspreadsheet svn, located at fpspreadsheet/examples/fpchart/fpchart.lpi

Please see the image bellow to see how the components are connected at design time. The TChart component can be edited by double-clicking. Then use the menus of the editor to add a new line serie and connect this line serie to our WorksheetChartSource by setting it's Source property.

Fpschart design.png

To load the data from the grid and into the chart a button was created with the following code. Notice that we can't just use any Grid, it has to be a FPSpreadsheet Grid, which has the class TsWorksheetGrid:

type
  
  { TFPSChartForm }

  TFPSChartForm = class(TForm)
    btnCreateGraphic: TButton;
    MyChart: TChart;
    FPSChartSource: TsWorksheetChartSource;
    MyChartLineSeries: TLineSeries;
    WorksheetGrid: TsWorksheetGrid;
    procedure btnCreateGraphicClick(Sender: TObject);
  private
    { private declarations }
  public
    { public declarations }
  end; 

...

procedure TFPSChartForm.btnCreateGraphicClick(Sender: TObject);
begin
  FPSChartSource.LoadFromWorksheetGrid(WorksheetGrid);
end;

And finally we can see how this works nicely in a running application in the picture bellow:

Fpschart run.png