FPSpreadsheet: Change signature of AddChart() methods. Adapt all sample projects.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@9442 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz 2024-09-15 21:28:40 +00:00
parent 0c4bdb63ad
commit 51c89b10ca
19 changed files with 37 additions and 35 deletions

View File

@ -74,8 +74,8 @@ begin
sheet.WriteText( 9, 0, 'Physics'); sheet.WriteNumber( 9, 1, 12); sheet.WriteNumber( 9, 2, 19);
sheet.WriteText(10, 0, 'Computer'); sheet.WriteNumber(10, 1, 16); sheet.WriteNumber(10, 2, 18);
// Create chart: left/top in cell D4, 160 mm x 100 mm
ch := book.AddChart(sheet, 2, 3, 160, 100);
// Create chart: left/top in cell D4 of worksheet "area_series", 160 mm x 100 mm
ch := sheet.AddChart(160, 100, 2, 3);
// Chart properties
ch.Border.Style := clsNoLine;

View File

@ -51,8 +51,8 @@ begin
sheet.WriteText( 7, 0, 'Case 5'); sheet.WriteNumber( 7, 1, 9); sheet.WriteNumber( 7, 2, 304);
sheet.WriteText( 8, 0, 'Case 6'); sheet.WriteNumber( 8, 1, 5); sheet.WriteNumber( 8, 2, 1285);
// Create chart: left/top in cell D4, 160 mm x 100 mm
ch := book.AddChart(sheet, 2, 3, 120, 100);
// Create chart: left/top in cell D4 of sheet "bar_series", 160 mm x 100 mm
ch := sheet.AddChart(120, 100, 2, 3);
// Chart properties
ch.Border.Style := clsNoLine;

View File

@ -59,7 +59,7 @@ begin
sheet.WriteText( 6, 0, 'Q4/2022'); sheet.WriteNumber( 6, 1, 311); sheet.WriteNumber( 6, 2, 183);
// Create chart: left/top in cell D4, 160 mm x 100 mm
ch := book.AddChart(sheet, 2, 3, 120, 100);
ch := sheet.AddChart(120, 100, 2, 3);
// Chart properties
if stackedPercentage then

View File

@ -80,7 +80,7 @@ begin
sheet.WriteText(10, 0, 'Computer'); sheet.WriteNumber(10, 1, 16); sheet.WriteNumber(10, 2, 18);
// Create chart: left/top in cell D4, 160 mm x 100 mm
ch := book.AddChart(sheet, 2, 3, 160, 100);
ch := sheet.AddChart(160, 100, 2, 3);
// Chart properties
ch.Border.Style := clsNoLine;

View File

@ -51,7 +51,7 @@ begin
sheet.WriteColWidth(2, 40.0, suMillimeters);
// Create chart: left/top in cell D4, 150 mm x 150 mm
ch := book.AddChart(sheet, 2, 4, 150, 150);
ch := sheet.AddChart(150, 150, 2, 4);
// Chart properties
ch.Border.Style := clsNoLine;

View File

@ -46,7 +46,7 @@ begin
sheet.WriteNumber(8, 0, 6.8); sheet.WriteNumber(8, 1, 71.3); sheet.WriteNumber(8, 2, 3.5);
// Create chart: left/top in cell D4, 150 mm x 100 mm
ch := book.AddChart(sheet, 2, 3, 150, 100);
ch := sheet.AddChart(150, 100, 2, 3);
// Chart properties
ch.Border.Style := clsNoLine;

View File

@ -75,7 +75,7 @@ begin
sheet.WriteText(10, 0, 'Computer'); sheet.WriteNumber(10, 1, 16); sheet.WriteNumber(10, 2, 18);
// Create chart: left/top in cell D4, 160 mm x 100 mm
ch := book.AddChart(sheet, 2, 3, 160, 100);
ch := sheet.AddChart(160, 100, 2, 3);
// Chart properties
ch.Border.Style := clsNoLine;
@ -100,7 +100,7 @@ begin
ser.SymbolFill.Color := ChartColor(scRed, 0.5);
ser.SymbolFill.Style := cfsSolid;
ser.SymbolBorder.Color := ChartColor(scBlack);
ser.Smooth := true;
ser.Interpolation := ciCubicSpline;
// ser.GroupIndex := -1;
// Add 2nd line series ("Student 2")

View File

@ -47,7 +47,7 @@ begin
sheet.WriteText(8, 0, 'Oceania'); sheet.WriteNumber(8, 1, 42); // sheet.WriteChartColor(8, 2, $FF8080);
// Create chart: left/top in cell D4, 150 mm x 150 mm
ch := book.AddChart(sheet, 2, 3, 150, 150);
ch := sheet.AddChart(150, 150, 2, 3);
// Chart properties
ch.Border.Style := clsNoLine;

View File

@ -38,7 +38,7 @@ begin
sheet.WriteText(10, 0, 'Computer'); sheet.WriteNumber(10, 1, 16); sheet.WriteNumber(10, 2, 18);
// Create chart: left/top in cell D4, 160 mm x 100 mm
ch := book.AddChart(sheet, 2, 3, 120, 100);
ch := sheet.AddChart(120, 100, 2, 3);
// Chart properties
ch.Border.Style := clsNoLine;

View File

@ -68,6 +68,10 @@ begin
end;
const
FOLDER = 'files/';
// Uncomment one of the following FILE_NAMEs
// FILE_NAME = 'test.ods';
// FILE_NAME = 'area.ods';
// FILE_NAME = 'bars.ods';
@ -81,14 +85,12 @@ var
series: TsChartSeries;
trendline: TsChartTrendline;
i, j: Integer;
isODS: Boolean;
begin
FormatSettings.DecimalSeparator := '.';
isODS := ExtractFileExt(FILE_NAME) = '.ods';
book := TsWorkbook.Create;
try
book.ReadFromFile(FILE_NAME);
book.ReadFromFile(FOLDER + FILE_NAME);
for i := 0 to book.GetChartCount-1 do
begin
chart := book.GetChartByIndex(i);

View File

@ -42,7 +42,7 @@ begin
sheet.WriteNumber(8, 0, 6.8); sheet.WriteNumber(8, 1, 71.3);
// Create chart: left/top in cell D4, 150 mm x 100 mm
ch := book.AddChart(sheet, 2, 3, 150, 100);
ch := book.AddChart(sheet, 150, 100, 2, 3);
// Chart properties
ch.Border.Style := clsNoLine;

View File

@ -97,7 +97,7 @@ begin
end;
// Create chart: left/top in cell D4, 160 mm x 100 mm
ch := book.AddChart(sheet, 2, 2, 160, 100);
ch := sheet.AddChart(160, 100, 2, 2);
// Chart properties
ch.Border.Style := clsNoLine;

View File

@ -113,7 +113,7 @@ begin
WriteData(r, d, 95000, 110, 119, 103, 115);
// Create chart: left/top in cell D4, 160 mm x 100 mm
ch := book.AddChart(sheet, 2, 6, 160, 100);
ch := sheet.AddChart(160, 100, 2, 6);
// Chart properties
ch.RotatedAxes := rotated;

View File

@ -87,7 +87,7 @@ begin
WriteData(r, d, 110, 119, 103, 115);
// Create chart: left/top in cell D4, 160 mm x 100 mm
ch := book.AddChart(sheet, 2, 5, 160, 100);
ch := book.AddChart(sheet, 160, 100, 2, 5);
// Chart properties
ch.Border.Style := clsNoLine;

View File

@ -56,7 +56,7 @@ begin
sheet1.WriteNumber(r2, 3, r2*r2);
// Create chart
ch := book.AddChart(sheet1, 4, 6, 160, 100);
ch := book.AddChart(sheet1, 160, 100, 4, 6);
// Add first series (type depending on SERIES_CLASS)
ser := SERIES_CLASS.Create(ch);

View File

@ -5154,7 +5154,7 @@ procedure TsSpreadOpenDocReader.ReadShape(ANode: TDOMNode;
if entry.IsChartRoot and ((entry.FileName = href) or ('./' + entry.FileName = href)) then
begin
(FWorksheet as TsWorksheet).CalcObjectCell(x, y, w, h, r, c, dy, dx);
chart := (FWorkbook as TsWorkbook).AddChart(FWorksheet, r, c, w, h, dx, dy);
chart := (FWorksheet as TsWorksheet).AddChart(w, h, r, c, dx, dy);
chart.Name := entry.FileName;
handled := true;
break;

View File

@ -644,8 +644,8 @@ type
{$ifdef FPS_CHARTS}
{ Chart support }
function AddChart(ARow, ACol: Cardinal;
AWidth, AHeight: Double; AOffsetX: Double = 0.0; AOffsetY: Double = 0.0): TsChart;
function AddChart(AWidth, AHeight: Double; ARow, ACol: Cardinal;
AOffsetX: Double = 0.0; AOffsetY: Double = 0.0): TsChart;
function GetChartCount: Integer;
procedure RemoveAllCharts;
procedure RemoveChart(AChart: TsChart);
@ -945,8 +945,8 @@ type
{$ifdef FPS_CHARTS}
{ Charts }
function AddChart(ASheet: TsBasicWorksheet; ARow, ACol: Cardinal;
AWidth, AHeight: Double; AOffsetX: Double = 0.0; AOffsetY: Double = 0.0): TsChart;
function AddChart(ASheet: TsBasicWorksheet; AWidth, AHeight: Double;
ARow, ACol: Cardinal; AOffsetX: Double = 0.0; AOffsetY: Double = 0.0): TsChart;
function GetChartByIndex(AIndex: Integer): TsChart;
function GetChartCount: Integer;
{$endif}

View File

@ -8,18 +8,18 @@
{@@ ----------------------------------------------------------------------------
Adds a chart to the worksheet.
@param ARow Index of the row in which the top of the chart should be positioned.
@param ACol Index of the column in which the left side of the chart should be positioned.
@param AWidth Width of the chart, in workbook units
@param AHeight Height of the chart, in workbook units
@param ARow Index of the row in which the top of the chart should be positioned.
@param ACol Index of the column in which the left side of the chart should be positioned.
@param AOffsetX Distance of the chart's left side from the left side of column ACol, in workbook units
@param AOffsetY Distance of the chart's top side from the top side of row ARow, in workbook units
@returns The instance of the created chart
-------------------------------------------------------------------------------}
function TsWorksheet.AddChart(ARow, ACol: Cardinal; AWidth, AHeight: Double;
function TsWorksheet.AddChart(AWidth, AHeight: Double; ARow, ACol: Cardinal;
AOffsetX: Double = 0.0; AOffsetY: Double = 0.0): TsChart;
begin
Result := Workbook.AddChart(self, ARow, ACol, AWidth, AHeight, AOffsetX, AOffsetY);
Result := Workbook.AddChart(self, AWidth, AHeight, ARow, ACol, AOffsetX, AOffsetY);
end;
{@@ ----------------------------------------------------------------------------
@ -76,21 +76,21 @@ end;
{@@ ----------------------------------------------------------------------------
Creates a chart object with its top/left corner in the specified row/colum and
having the specified width (in workbook units).
having the specified width and height (in workbook units).
Inserts the chart in the internal FCharts list of the workbook and returns
the chart instance.
@param ASheet Worksheet into which the chart will be inserted.
@param ARow Index of the row in which the top of the chart should be positioned.
@param ACol Index of the column in which the left side of the chart should be positioned.
@param AWidth Width of the chart, in workbook units (usually millimeters)
@param AHeight Height of the chart, in workbook units
@param ARow Index of the row in which the top of the chart should be positioned.
@param ACol Index of the column in which the left side of the chart should be positioned.
@param AOffsetX Distance of the chart's left side from the left side of column ACol, in workbook units
@param AOffsetY Distance of the chart's top side from the top side of row ARow, in workbook units
@returns The instance of the created chart
-------------------------------------------------------------------------------}
function TsWorkbook.AddChart(ASheet: TsBasicWorksheet; ARow, ACol: Cardinal;
AWidth, AHeight: Double; AOffsetX: Double = 0.0; AOffsetY: Double = 0.0): TsChart;
function TsWorkbook.AddChart(ASheet: TsBasicWorksheet; AWidth, AHeight: Double;
ARow, ACol: Cardinal; AOffsetX: Double = 0.0; AOffsetY: Double = 0.0): TsChart;
begin
Result := TsChart.Create;
if (ASheet = nil) then

View File

@ -3044,7 +3044,7 @@ begin
w := w + sheet.GetColWidth(j, suMillimeters);
for j := data.FromRow to data.ToRow-1 do
h := h + sheet.GetRowHeight(j, suMillimeters);
chart := TsWorkbook(FWorkbook).AddChart(sheet, data.FromRow, data.FromCol, w, h, data.FromRowOffs, data.FromColOffs);
chart := sheet.AddChart(w, h, data.FromRow, data.FromCol, data.FromRowOffs, data.FromColOffs);
TsSpreadOOXMLChartReader(FChartReader).ReadChartXML(AStream, chart, data.MediaName);
end else
{$endif}