fpspreadsheet: xlsx writer supports individual data point styles.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@9210 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz 2024-02-04 14:47:25 +00:00
parent 6bbfc0e6fc
commit b476a26d90
5 changed files with 55 additions and 22 deletions

View File

@ -49,6 +49,7 @@
<Linking>
<Debugging>
<DebugInfoType Value="dsDwarf3"/>
<UseHeaptrc Value="True"/>
</Debugging>
</Linking>
</CompilerOptions>

View File

@ -13,6 +13,8 @@ var
sheet: TsWorksheet;
ch: TsChart;
ser: TsChartSeries;
fill: TsChartFill;
line: TsChartLine;
begin
book := TsWorkbook.Create;
try
@ -54,16 +56,17 @@ begin
ser.DataLabels := [cdlCategory, cdlValue];
ser.LabelSeparator := '\n'; // this is the symbol for a line-break
ser.LabelPosition := lpOutside;
ser.Line.Color := scWhite;
ser.LabelFormat := '#,##0';
// Individual sector colors
// Individual sector colors, with white border
// Must be complete, otherwise will be ignored by Calc and replaced by default colors
ser.DataPointStyles.AddSolidFill($C47244);
ser.DataPointStyles.AddSolidFill($317DED);
ser.DataPointStyles.AddSolidFill($A5A5A5);
ser.DataPointStyles.AddSolidFill($00C0FF);
ser.DataPointStyles.AddSolidFill($D69B5B);
line := TsChartline.CreateSolid(scWhite, 0.8);
ser.DataPointStyles.AddSolidFill($C47244, line);
ser.DataPointStyles.AddSolidFill($317DED, line);
ser.DataPointStyles.AddSolidFill($A5A5A5, line);
ser.DataPointStyles.AddSolidFill($00C0FF, line);
ser.DataPointStyles.AddSolidFill($D69B5B, line);
line.Free;
//ser.SetFillColorRange(4, 2, 8, 2);

View File

@ -41,6 +41,7 @@ type
Width: Double; // mm
Color: TsColor; // in hex: $00bbggrr, r=red, g=green, b=blue
Transparency: Double; // in percent
constructor CreateSolid(AColor: TsColor; AWidth: Double);
procedure CopyFrom(ALine: TsChartLine);
end;
@ -408,7 +409,7 @@ type
public
constructor Create(AChart: TsChart);
function AddFillAndLine(AFill: TsChartFill; ALine: TsChartline; ACount: Integer = 1): Integer;
function AddSolidFill(AColor: TsColor; ACount: Integer = 1): Integer;
function AddSolidFill(AColor: TsColor; ALine: TsChartLine = nil; ACount: Integer = 1): Integer;
property Items[AIndex: Integer]: TsChartDataPointStyle read GetItem write SetItem; default;
end;
@ -884,6 +885,14 @@ uses
{ TsChartLine }
constructor TsChartLine.CreateSolid(AColor: TsColor; AWidth: Double);
begin
inherited Create;
Style := clsSolid;
Color := AColor;
Width := AWidth;
end;
procedure TsChartLine.CopyFrom(ALine: TsChartLine);
begin
if ALine <> nil then
@ -1941,7 +1950,8 @@ begin
end;
end;
function TsChartDataPointStyleList.AddSolidFill(AColor: TsColor; ACount: Integer = 1): Integer;
function TsChartDataPointStyleList.AddSolidFill(AColor: TsColor;
ALine: TsChartLine = nil; ACount: Integer = 1): Integer;
var
fill: TsChartFill;
begin
@ -1949,7 +1959,7 @@ begin
try
fill.Style := cfsSolid;
fill.Color := AColor;
Result := AddFillAndLine(fill, nil, ACount);
Result := AddFillAndLine(fill, ALine, ACount);
finally
fill.Free;
end;

View File

@ -4031,6 +4031,9 @@ var
xRng, yRng: TsChartRange;
forceNoLine: Boolean;
xValName, yValName, xRefName, yRefName: String;
explosionStr: String = '';
dps: TsChartDataPointStyle;
i: Integer;
begin
indent := DupeString(' ', AIndent);
chart := ASeries.Chart;
@ -4051,6 +4054,22 @@ begin
// Series title
WriteChartSeriesTitle(AStream, AIndent + 2, ASeries);
// Individual data point formats
if ASeries.DataPointStyles.Count > 0 then
for i := 0 to ASeries.DataPointStyles.Count-1 do
begin
dps := ASeries.DataPointStyles[i];
AppendToStream(AStream,
indent + ' <c:dPt>' + LE +
indent + ' <c:idx val="' + IntToStr(i) + '"/>' + LE +
explosionStr + // to do: read explosion value from worksheet!
indent + ' <c:spPr>' + LE +
GetChartFillAndLineXML(AIndent + 6, chart, dps.Background, dps.Border) + LE +
indent + ' </c:spPr>' + LE +
indent + ' </c:dPt>' + LE
);
end;
// Line & scatter series: symbol markers
if (ASeries is TsCustomLineSeries) then
begin

View File

@ -163,7 +163,7 @@ type
procedure UpdateChartLegend(AWorkbookLegend: TsChartLegend; ALegend: TChartLegend);
procedure UpdateChartPen(AWorkbookChart: TsChart; AWorkbookLine: TsChartLine; APen: TPen);
procedure UpdateChartSeriesMarks(AWorkbookSeries: TsChartSeries; AChartSeries: TChartSeries);
procedure UpdateChartSeriesRegression(AWorkbookSeries: TsChartSeries; AChartSeries: TChartSeries);
procedure UpdateChartSeriesTrendline(AWorkbookSeries: TsChartSeries; AChartSeries: TChartSeries);
procedure UpdateChartStyle(AWorkbookSeries: TsChartSeries; AStyleIndex: Integer);
procedure UpdateChartTitle(AWorkbookTitle: TsChartText; AChartTitle: TChartTitle);
@ -1859,8 +1859,8 @@ begin
if AChartSeries.Source is TCalculatedChartSource then
TCalculatedChartSource(AChartSeries.Source).Percentage := (AWorkbookSeries.Chart.StackMode = csmStackedPercentage);
// Regression/trend line
UpdateChartSeriesRegression(AWorkbookSeries, AChartSeries);
// Trend line
UpdateChartSeriesTrendline(AWorkbookSeries, AChartSeries);
// Error bars
UpdateChartErrorBars(AWorkbookSeries, AChartSeries);
@ -1898,8 +1898,8 @@ begin
if AChartSeries.Source is TCalculatedChartSource then
TCalculatedChartSource(AChartSeries.Source).Percentage := (AWorkbookSeries.Chart.StackMode = csmStackedPercentage);
// Regression/trend line
UpdateChartSeriesRegression(AWorkbookSeries, AChartSeries);
// Trend line
UpdateChartSeriesTrendLine(AWorkbookSeries, AChartSeries);
end;
procedure TsWorkbookChartlink.UpdateBubbleSeries(AWorkbookSeries: TsBubbleSeries;
@ -1917,8 +1917,8 @@ begin
AChartSeries.ParentChart.ExpandPercentage := 10;
{$IFEND}
// Regression/trend line
UpdateChartSeriesRegression(AWorkbookSeries, AChartSeries);
// Trend line
UpdateChartSeriesTrendline(AWorkbookSeries, AChartSeries);
end;
procedure TsWorkbookChartLink.UpdateChart;
@ -2431,7 +2431,7 @@ begin
end;
end;
procedure TsWorkbookChartLink.UpdateChartSeriesRegression(AWorkbookSeries: TsChartSeries;
procedure TsWorkbookChartLink.UpdateChartSeriesTrendline(AWorkbookSeries: TsChartSeries;
AChartSeries: TChartSeries);
var
trendlineSeries: TsOpenedTrendlineSeries;
@ -2585,8 +2585,8 @@ begin
// Error bars
UpdateChartErrorBars(AWorkbookSeries, AChartSeries);
// Regression/trend line
UpdateChartSeriesRegression(AWorkbookSeries, AChartSeries);
// Trend line
UpdateChartSeriesTrendline(AWorkbookSeries, AChartSeries);
end;
procedure TsWorkbookChartLink.UpdatePieSeries(AWorkbookSeries: TsPieSeries;
@ -2664,8 +2664,8 @@ begin
AChartSeries.TickWidthStyle := twsPercentMin;
AChartSeries.TickWidth := AWorkbookSeries.TickWidthPercent div 2;
// Regression/trend line
UpdateChartSeriesRegression(AWorkbookSeries, AChartSeries);
// Trend line
UpdateChartSeriesTrendline(AWorkbookSeries, AChartSeries);
end;
{$ENDIF}