fpspreadsheet: More work on ods writer of charts

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@8978 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2023-10-25 17:15:57 +00:00
parent 97ec0cb837
commit b00a15e563
4 changed files with 1354 additions and 575 deletions

View File

@ -16,10 +16,12 @@ begin
// 1st sheet
sh1 := b.AddWorksheet('test1');
sh1.WriteText(0, 1, 'sin(x)');
sh1.WriteText(0, 2, 'sin(x/2)');
for i := 1 to 7 do
begin
sh1.WriteNumber(i, 0, i-1);
sh1.WriteNumber(i, 1, sin(i-1));
sh1.WriteNumber(i, 2, sin((i-1)/2));
end;
ch := b.AddChart(sh1, 4, 4, 160, 100);
@ -27,10 +29,18 @@ begin
ser.SetTitleAddr(0, 1);
ser.SetLabelRange(1, 0, 7, 0);
ser.SetYRange(1, 1, 7, 1);
ser.Line.Color := scBlue;
TsLineSeries(ser).ShowSymbols := true;
TsLineSeries(ser).Symbol := cssCircle;
ser := TsLineSeries.Create(ch);
ser.SetTitleAddr(0, 2);
ser.SetLabelRange(1, 0, 7, 0);
ser.SetYRange(1, 2, 7, 2);
ser.Line.Color := scRed;
TsLineSeries(ser).ShowSymbols := true;
TsLineSeries(ser).Symbol := cssDiamond;
ch.Background.Style := fsSolidFill;
ch.Border.Style := clsSolid;
ch.PlotArea.Background.Style := fsSolidFill;
{$IFDEF DARK_MODE}
ch.Background.FgColor := scBlack;
ch.Border.Color := scWhite;
@ -40,23 +50,38 @@ begin
ch.Border.Color := scBlack;
ch.PlotArea.Background.FgColor := $F0F0F0;
{$ENDIF}
// Background and wall working
ch.Background.Style := fsSolidFill;
ch.Border.Style := clsSolid;
ch.PlotArea.Background.Style := fsSolidFill;
ch.XAxis.ShowLabels := true;
ch.XAxis.LabelFont.Size := 8;
ch.XAxis.LabelFont.Color := scRed;
ch.XAxis.LabelFont.Style := [fssStrikeout];
ch.XAxis.AxisLine.Color := scRed;
ch.XAxis.Caption := 'This is the x axis';
ch.XAxis.CaptionFont.Color := scRed;
ch.XAxis.CaptionFont.Size := 12;
ch.XAxis.Inverted := true;
ch.XAxis.MajorGridLines.Color := scRed;
ch.XAxis.MinorGridLines.Color := scBlue;
ch.XAxis.MajorGridLines.Style := clsNoLine;//Solid;
ch.XAxis.MinorGridLines.Style := clsNoLine; //Solid;
ch.YAxis.ShowLabels := true;
ch.YAxis.LabelFont.Size := 8;
ch.YAxis.LabelFont.Color := scBlue;
ch.YAxis.AxisLine.Color := scBlue;
ch.YAxis.Caption := 'This is the y axis';
ch.YAxis.CaptionFont.Color := scBlue;
ch.YAxis.CaptionFont.Size := 12;
ch.YAxis.LabelRotation := 90;
ch.YAxis.CaptionRotation := 90;
ch.YAxis.MajorGridLines.Style := clsLongDash; //clsSolid;
ch.YAxis.MinorGridLines.Style := clsLongDashDot; //Dash; //clsSolid;
ch.YAxis.MajorGridLines.Color := scBlue;
ch.YAxis.MajorGridLines.Width := 1; // mm
ch.Title.Caption := 'HALLO';
ch.Title.Visible := true;
@ -64,14 +89,13 @@ begin
ch.SubTitle.Caption := 'hallo';
ch.SubTitle.Visible := true;
ch.YAxis.MajorGridLines.Style := clsSolid;
ch.YAxis.MinorGridLines.Style := clsSolid;
ch.Legend.Font.Size := 20;
ch.Legend.Font.Color := scGreen;
ch.Legend.Border.Width := 3;
ch.Legend.Border.Color := scRed;
ch.Legend.Background.FgColor := scYellow;
// Legend working
ch.Legend.Font.Size := 12;
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.Style := fsSolidFill;
// 2nd sheet
@ -101,15 +125,22 @@ begin
ch.Title.Visible := true;
ch.SubTitle.Caption := 'hallo';
ch.Subtitle.Visible := true;
ch.XAxis.MajorGridLines.Style := clsNoLine;
ch.XAxis.MajorGridLines.Style := clsSolid; //NoLine;
ch.XAxis.MinorGridLines.Style := clsNoLine;
ch.YAxis.MajorGridLines.Style := clsNoLine;
ch.YAxis.MinorGridLines.Style := clsNoLine;
ch.YAxis.CaptionRotation := 0;
ch.XAxis.CaptionFont.Size := 18;
ch.YAxis.CaptionFont.Size := 18;
ch.XAxis.LabelFont.Style := [fssItalic];
ch.YAxis.LabelFont.Style := [fssItalic];
b.WriteToFile('test.xlsx', true); // Excel fails to open the file
b.WriteToFile('test.ods', true);
finally
b.Free;
end;
ReadLn;
end.

View File

@ -28,6 +28,10 @@ const
DEFAULT_CHART_LINEWIDTH = 0.75; // pts
DEFAULT_CHART_FONT = 'Arial';
DEFAULT_SERIES_COLORS: array[0..7] of TsColor = (
scRed, scBlue, scGreen, scMagenta, scPurple, scTeal, scBlack, scGray
);
type
TsChart = class;
@ -184,8 +188,12 @@ type
FYAxis: TsChartAxisLink;
FTitleAddr: TsCellCoord;
FLabelFormat: String;
FLine: TsChartLine;
FFill: TsChartFill;
FBorder: TsChartLine;
public
constructor Create(AChart: TsChart);
destructor Destroy; override;
function GetCount: Integer;
function GetXCount: Integer;
function GetYCount: Integer;
@ -207,6 +215,10 @@ type
property XRange: TsCellRange read FXRange;
property YRange: TsCellRange read FYRange;
property YAxis: TsChartAxisLink read FYAxis write FYAxis;
property Border: TsChartLine read FBorder write FBorder;
property Fill: TsChartFill read FFill write FFill;
property Line: TsChartLine read FLine write FLine;
end;
TsChartSeriesSymbol = (
@ -216,21 +228,22 @@ type
TsLineSeries = class(TsChartSeries)
private
FLine: TsChartLine;
FSymbol: TsChartSeriesSymbol;
FSymbolFill: TsChartFill;
FSymbolBorder: TsChartLine;
FSymbolHeight: Double; // in mm
FSymbolWidth: Double; // in mm
FShowSymbols: Boolean;
function GetSymbolBorder: TsChartLine;
function GetSymbolFill: TsChartFill;
procedure SetSymbolBorder(Value: TsChartLine);
procedure SetSymbolFill(Value: TsChartFill);
public
constructor Create(AChart: TsChart);
destructor Destroy; override;
property Line: TsChartLine read FLine write FLine;
property Symbol: TsChartSeriesSymbol read FSymbol write FSymbol;
property SymbolBorder: TsChartLine read FSymbolBorder write FSymbolBorder;
property SymbolFill: TsChartFill read FSymbolFill write FSymbolFill;
property SymbolBorder: TsChartLine read GetSymbolBorder write SetSymbolBorder;
property SymbolFill: TsChartFill read GetSymbolFill write SetSymbolFill;
property SymbolHeight: double read FSymbolHeight write FSymbolHeight;
property SymbolWidth: double read FSymbolWidth write FSymbolWidth;
property ShowSymbols: Boolean read FShowSymbols write FShowSymbols;
end;
TsChartSeriesList = class(TFPList)
@ -482,7 +495,7 @@ begin
FMinorGridLines := TsChartLine.Create;
FMinorGridLines.Color := scSilver;
FMinorGridLines.Style := clsDot;
FMinorGridLines.Style := clsDash;
FMinorGridLines.Width := PtsToMM(DEFAULT_CHART_LINEWIDTH);
end;
@ -519,9 +532,35 @@ end;
{ TsChartSeries }
constructor TsChartSeries.Create(AChart: TsChart);
var
idx: Integer;
begin
inherited Create(AChart);
AChart.AddSeries(self);
idx := AChart.AddSeries(self);
FBorder := TsChartLine.Create;
FBorder.Style := clsSolid;
FBorder.Width := PtsToMM(DEFAULT_CHART_LINEWIDTH);
FBorder.Color := scBlack;
FFill := TsChartFill.Create;
FFill.Style := fsSolidFill;
FFill.FgColor := DEFAULT_SERIES_COLORS[idx mod Length(DEFAULT_SERIES_COLORS)];
FFill.BgColor := DEFAULT_SERIES_COLORS[idx mod Length(DEFAULT_SERIES_COLORS)];
FLine := TsChartLine.Create;
FLine.Style := clsSolid;
FLine.Width := PtsToMM(DEFAULT_CHART_LINEWIDTH);
FLine.Color := DEFAULT_SERIES_COLORS[idx mod Length(DEFAULT_SERIES_COLORS)];
end;
destructor TsChartSeries.Destroy;
begin
FLine.Free;
FFill.Free;
FBorder.Free;
inherited;
end;
function TsChartSeries.GetCount: Integer;
@ -633,34 +672,29 @@ end;
constructor TsLineSeries.Create(AChart: TsChart);
begin
inherited Create(AChart);
FChartType := ctLine;
FLine := TsChartLine.Create;
FLine.Color := scBlack;
FLine.Style := clsSolid;
FLine.Width := PtsToMM(DEFAULT_CHART_LINEWIDTH);
FSymbolBorder := TsChartline.Create;
FSymbolBorder.Color := scBlack;
FSymbolBorder.Style := clsSolid;
FSymbolBorder.Width := PtsToMM(DEFAULT_CHART_LINEWIDTH);
FSymbolFill := TsChartFill.Create;
FSymbolFill.FgColor := scWhite;
FSymbolFill.BgColor := scWhite;
FSymbolFill.Style := fsSolidFill;
FSymbolWidth := 2.5;
FSymbolHeight := 2.5;
end;
destructor TsLineSeries.Destroy;
function TsLineSeries.GetSymbolBorder: TsChartLine;
begin
FSymbolFill.Free;
FSymbolBorder.Free;
FLine.Free;
inherited;
Result := FBorder;
end;
function TsLineSeries.GetSymbolFill: TsChartFill;
begin
Result := FFill;
end;
procedure TsLineSeries.SetSymbolBorder(Value: TsChartLine);
begin
FBorder := Value;
end;
procedure TsLineSeries.SetSymbolFill(Value: TsChartFill);
begin
FFill := Value;
end;

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff