diff --git a/components/fpspreadsheet/examples/other/chart/write_chart_demo.lpr b/components/fpspreadsheet/examples/other/chart/write_chart_demo.lpr
index 00b4a107f..d8d1f2872 100644
--- a/components/fpspreadsheet/examples/other/chart/write_chart_demo.lpr
+++ b/components/fpspreadsheet/examples/other/chart/write_chart_demo.lpr
@@ -98,9 +98,10 @@ begin
ch.Legend.Font.Color := scBlue;
ch.Legend.Border.Width := 0.3; // mm
ch.Legend.Border.Color := scGray;
- ch.Legend.Background.FgColor := scSilver;
+ ch.Legend.Background.FgColor := $F0F0F0;
ch.Legend.Background.Style := fsSolidFill;
- ch.Legend.CanOverlapPlotArea := true;
+ //ch.Legend.CanOverlapPlotArea := true;
+ ch.Legend.Position := lpBottom;
// 2nd sheet
sh2 := b.AddWorksheet('test2');
diff --git a/components/fpspreadsheet/source/common/fpschart.pas b/components/fpspreadsheet/source/common/fpschart.pas
index 1872fac5e..3f6ef1668 100644
--- a/components/fpspreadsheet/source/common/fpschart.pas
+++ b/components/fpspreadsheet/source/common/fpschart.pas
@@ -168,15 +168,19 @@ type
property ShowLabels: Boolean read FShowLabels write FShowLabels;
end;
+ TsChartLegendPosition = (lpRight, lpTop, lpBottom, lpLeft);
+
TsChartLegend = class(TsChartFillElement)
private
FFont: TsFont;
FCanOverlapPlotArea: Boolean;
+ FPosition: TsChartLegendPosition;
public
constructor Create(AChart: TsChart);
destructor Destroy; override;
property CanOverlapPlotArea: Boolean read FCanOverlapPlotArea write FCanOverlapPlotArea;
property Font: TsFont read FFont write FFont;
+ property Position: TsChartLegendPosition read FPosition write FPosition;
end;
TsChartAxisLink = (alPrimary, alSecondary);
diff --git a/components/fpspreadsheet/source/common/fpschartstyles.pas b/components/fpspreadsheet/source/common/fpschartstyles.pas
index 866e565c8..1d82096ad 100644
--- a/components/fpspreadsheet/source/common/fpschartstyles.pas
+++ b/components/fpspreadsheet/source/common/fpschartstyles.pas
@@ -97,6 +97,7 @@ type
Font: TsChartFontRec;
Border: TsChartLineRec;
Fill: TsChartFillRec;
+ Position: TsChartLegendPosition;
Visible: Boolean;
procedure FromChart(AChart: TsChart; AElement: TsChartStyleElement);
procedure ToChart(AChart: TsChart; AElement: TsChartStyleElement);
@@ -605,6 +606,7 @@ begin
Border.FromChart(AChart, ceLegend, 0);
Fill.FromChart(AChart, ceLegend, 0);
Visible := AChart.Legend.Visible;
+ Position := AChart.Legend.Position;
end;
procedure TsChartLegendRec.ToChart(AChart: TsChart; AElement: TsChartStyleElement);
@@ -614,12 +616,14 @@ begin
Border.ToChart(AChart, ceLegend, 0);
Fill.ToChart(AChart, ceLegend, 0);
AChart.Legend.Visible := Visible;
+ AChart.Legend.Position := Position;
end;
class operator TsChartLegendRec.= (A, B: TsChartLegendRec): Boolean;
begin
Result := (A.Font = B.Font) and (A.Border = B.Border) and (A.Fill = B.Fill) and
- (A.Visible = B.Visible) and (A.CanOverlapPlotArea = B.CanOverlapPlotArea);
+ (A.Visible = B.Visible) and (A.CanOverlapPlotArea = B.CanOverlapPlotArea) and
+ (A.Position = B.Position);
end;
{ TsChartPlotAreaRec }
diff --git a/components/fpspreadsheet/source/common/fpsopendocument.pas b/components/fpspreadsheet/source/common/fpsopendocument.pas
index de7734224..4605765c9 100644
--- a/components/fpspreadsheet/source/common/fpsopendocument.pas
+++ b/components/fpspreadsheet/source/common/fpsopendocument.pas
@@ -7002,6 +7002,10 @@ end;
{ Writes the chart's legend to the xml stream }
procedure TsSpreadOpenDocWriter.WriteChartLegend(AStream: TStream; AChart: TsChart;
AIndent: Integer);
+const
+ LEGEND_POSITION: array[TsChartLegendPosition] of string = (
+ 'end', 'top', 'bottom', 'start'
+ );
var
ind: String;
styles: TsChartStyleList;
@@ -7020,8 +7024,8 @@ begin
canOverlap := 'loext:overlay="true" ';
ind := DupeString(' ', AIndent);
AppendToStream(AStream, Format(
- ind + '' + LE,
- [ idx + 1, canOverlap ]
+ ind + '' + LE,
+ [ idx + 1, LEGEND_POSITION[style.Legend.Position], canOverlap ]
));
{$ifdef DEBUG_CHART_STYLES}