fpspreadsheet: xlsx chart writer supports manual axis scaling.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@9206 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz 2024-02-03 16:51:59 +00:00
parent 33974c6cb0
commit a19317f379
4 changed files with 102 additions and 10 deletions

View File

@ -54,10 +54,12 @@ begin
ch.XAxis.Title.Caption := 'Distance from Sun (relative to Earth)';
ch.XAxis.MinorGridLines.Style := clsNoLine;
ch.XAxis.Logarithmic := true;
ch.XAxis.Max := 100;
ch.YAxis.Title.Caption := 'Orbital period (relative to Earth)';
ch.YAxis.AxisLine.Color := scSilver;
ch.YAxis.MinorGridLines.Style := clsNoLine;
ch.YAxis.Logarithmic := true;
ch.YAxis.Max := 1000;
// Add data as bubble series
ser := TsBubbleSeries.Create(ch);

View File

@ -100,12 +100,14 @@ begin
ch.Legend.Border.Style := clsNoLine;
// Set up logarithmic axes if needed.
case mode of
0: ;
0: begin
ch.XAxis.MajorInterval := 20;
ch.XAxis.MinorInterval := 5;
end;
1: ch.YAxis.Logarithmic := true;
2: begin
ch.XAxis.Logarithmic := true;
ch.XAxis.Max := 100;
ch.XAxis.AutomaticMax := false;
ch.YAxis.Logarithmic := true;
end;
end;
@ -114,7 +116,7 @@ begin
ser := TsScatterSeries.Create(ch);
// Series properties
ser.SetTitleAddr(0, 0);
ser.SetTitleAddr(0, 0); // A1
ser.SetXRange(3, 0, 10, 0); // A4:A11
ser.SetYRange(3, 1, 10, 1); // B4:B11
ser.ShowLines := true;

View File

@ -321,6 +321,11 @@ type
FPositionValue: Double;
FShowLabels: Boolean;
FDateTime: Boolean;
procedure SetMax(AValue: Double);
procedure SetMin(AValue: Double);
procedure SetMinorCount(AValue: Integer);
procedure SetMajorInterval(AValue: Double);
procedure SetMinorInterval(AValue: Double);
public
constructor Create(AChart: TsChart);
destructor Destroy; override;
@ -348,13 +353,13 @@ type
property Logarithmic: Boolean read FLogarithmic write FLogarithmic;
property LogBase: Double read FLogBase write FLogBase;
property MajorGridLines: TsChartLine read FMajorGridLines write FMajorGridLines;
property MajorInterval: Double read FMajorInterval write FMajorInterval;
property MajorInterval: Double read FMajorInterval write SetMajorInterval;
property MajorTicks: TsChartAxisTicks read FMajorTicks write FMajorTicks;
property Max: Double read FMax write FMax;
property Min: Double read FMin write FMin;
property Max: Double read FMax write SetMax;
property Min: Double read FMin write SetMin;
property MinorGridLines: TsChartLine read FMinorGridLines write FMinorGridLines;
property MinorCount: Integer read FMinorCount write FMinorCount;
property MinorInterval: Double read FMinorInterval write FMinorInterval;
property MinorCount: Integer read FMinorCount write SetMinorCount;
property MinorInterval: Double read FMinorInterval write SetMinorInterval;
property MinorTicks: TsChartAxisTicks read FMinorTicks write FMinorTicks;
property Position: TsChartAxisPosition read FPosition write FPosition;
property PositionValue: Double read FPositionValue write FPositionValue;
@ -869,7 +874,7 @@ type
implementation
uses
fpSpreadsheet;
Math, fpSpreadsheet;
{ TsChartLine }
@ -1663,6 +1668,7 @@ begin
FAutomaticMin := true;
FAutomaticMax := true;
FAutomaticMajorInterval := true;
FAutomaticMinorInterval := true;
FAutomaticMinorSteps := true;
FCategoryRange := TsChartRange.Create(AChart);
@ -1801,6 +1807,63 @@ begin
FCategoryRange.Col2 := ACol2;
end;
procedure TsChartAxis.SetMajorInterval(AValue: Double);
begin
if IsNaN(AValue) or (AValue <= 0) then
FAutomaticMajorInterval := true
else
begin
FAutomaticMajorInterval := false;
FMajorInterval := AValue;
end;
end;
procedure TsChartAxis.SetMax(AValue: Double);
begin
if IsNaN(AValue) then
FAutomaticMax := true
else
begin
FAutomaticMax := false;
FMax := AValue;
end;
end;
procedure TsChartAxis.SetMin(AValue: Double);
begin
if IsNaN(AValue) then
FAutomaticMin := true
else
begin
FAutomaticMin := false;
FMin := AValue;
end;
end;
procedure TsChartAxis.SetMinorCount(AValue: Integer);
begin
if IsNaN(AValue) or (AValue < 0) then
FAutomaticMinorSteps := true
else
begin
FAutomaticMinorSteps := false;
FMinorCount := AValue;
end;
end;
procedure TsChartAxis.SetMinorInterval(AValue: Double);
begin
if IsNaN(AValue) or (AValue < 0) then
FAutomaticMinorInterval := true
else
begin
FAutomaticMinorInterval := false;
FMinorInterval := AValue;
end;
end;
{ TsChartLegend }
constructor TsChartLegend.Create(AChart: TsChart);

View File

@ -3415,6 +3415,7 @@ begin
AppendToStream(AStream, Format(
indent + '<c:barChart>' + LE +
indent + ' <c:barDir val="col"/>' + LE +
indent + ' <c:varyColors val="0"/>' + LE +
indent + ' <c:grouping val="%s"/>' + LE,
[ GROUPING[chart.StackMode] ]
));
@ -3461,7 +3462,8 @@ begin
chart := ASeries.Chart;
AppendToStream(AStream,
indent + '<c:bubbleChart>' + LE
indent + '<c:bubbleChart>' + LE +
indent + ' <c:varyColors val="0"/>' + LE
);
WriteChartSeriesNode(AStream, AIndent + 2, ASeries, ASeriesIndex);
@ -3588,19 +3590,41 @@ procedure TsSpreadOOXMLChartWriter.WriteChartAxisScaling(AStream: TStream;
AIndent: Integer; Axis: TsChartAxis);
var
indent: String;
intv: Double;
logStr: String = '';
maxStr: String = '';
minStr: String = '';
begin
indent := DupeString(' ', AIndent);
if not Axis.AutomaticMax then
maxStr := indent + Format(' <c:max val="%g"/>', [Axis.Max], FPointSeparatorSettings) + LE;
if not Axis.AutomaticMin then
minStr := indent + Format(' <c:min val="&g"/>', [Axis.Min], FPointSeparatorSettings) + LE;
if Axis.Logarithmic then
logStr := indent + Format(' <c:logBase val="%g"/>', [Axis.LogBase], FPointSeparatorSettings) + LE;
AppendToStream(AStream,
indent + '<c:scaling>' + LE +
maxStr +
minStr +
logStr +
indent + ' <c:orientation val="minMax"/>' + LE +
indent + '</c:scaling>' + LE
);
// The following nodes are outside the <c:scaling node> !
if not Axis.AutomaticMajorInterval then
AppendToStream(AStream, Format(
indent + '<c:majorUnit val="%g"/>', [Axis.MajorInterval], fPointSeparatorSettings) + LE
);
if not Axis.AutomaticMinorInterval then
AppendToStream(AStream, Format(
indent + '<c:minorUnit val="%g"/>', [Axis.MinorInterval], FPointSeparatorSettings) + LE
);
end;
procedure TsSpreadOOXMLChartWriter.WriteChartAxisTitle(AStream: TStream;
@ -3873,6 +3897,7 @@ begin
AppendToStream(AStream,
indent + '<c:scatterChart>' + LE +
indent + ' <c:varyColors val="0"/>' + LE +
indent + ' <c:scatterStyle val="lineMarker"/>' + LE
);