TsWorksheetChartSource
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 with the TChart component from the TAChartLazarusPkg package, which usually comes pre-installed with Lazarus.
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.
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> 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; </delphi>
And finally we can see how this works nicely in a running application in the picture bellow: