fpspreadsheet: Chart link supports rotated axes.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@9094 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2023-12-19 12:30:16 +00:00
parent 2966f77529
commit 41fda1fbfb
6 changed files with 56 additions and 13 deletions

View File

@ -13,7 +13,14 @@ var
sheet: TsWorksheet;
ch: TsChart;
ser: TsScatterSeries;
fn: String;
rotated: Boolean;
begin
fn := FILE_NAME;
rotated := (ParamCount >= 1) and (lowercase(ParamStr(1)) = 'rotated');
if rotated then
fn := fn + '-rotated';
book := TsWorkbook.Create;
try
// Worksheet
@ -23,12 +30,12 @@ begin
sheet.WriteText(0, 0, 'Data');
sheet.WriteFont(0, 0, '', 12, [fssBold], scBlack);
sheet.WriteText (2, 0, 'x'); sheet.Writetext (2, 1, 'y');
sheet.WriteNumber(3, 0, 1.1); sheet.WriteNumber(3, 1, 0.9);
sheet.WriteNumber(4, 0, 1.9); sheet.WriteNumber(4, 1, 2.05);
sheet.WriteNumber(5, 0, 2.5); sheet.WriteNumber(5, 1, 2.45);
sheet.WriteNumber(6, 0, 3.1); sheet.WriteNumber(6, 1, 3.3);
sheet.WriteNumber(7, 0, 5.2); sheet.WriteNumber(7, 1, 4.9);
sheet.WriteNumber(8, 0, 6.8); sheet.WriteNumber(8, 1, 7.1);
sheet.WriteNumber(3, 0, 1.1); sheet.WriteNumber(3, 1, 9.0);
sheet.WriteNumber(4, 0, 1.9); sheet.WriteNumber(4, 1, 20.5);
sheet.WriteNumber(5, 0, 2.5); sheet.WriteNumber(5, 1, 24.5);
sheet.WriteNumber(6, 0, 3.1); sheet.WriteNumber(6, 1, 33.2);
sheet.WriteNumber(7, 0, 5.2); sheet.WriteNumber(7, 1, 49.4);
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);
@ -36,6 +43,7 @@ begin
// Chart properties
ch.Border.Style := clsNoLine;
ch.Legend.Border.Style := clsNoLine;
ch.RotatedAxes := rotated;
// Add scatter series
ser := TsScatterSeries.Create(ch);
@ -69,12 +77,12 @@ begin
//ser.Regression.Equation.Left := 5;
{
book.WriteToFile(FILE_NAME + '.xlsx', true); // Excel fails to open the file
WriteLn('Data saved with chart to ', FILE_NAME, '.xlsx');
book.WriteToFile(fn + '.xlsx', true); // Excel fails to open the file
WriteLn('Data saved with chart to ', fn, '.xlsx');
}
book.WriteToFile('regression.ods', true);
WriteLn('Data saved with chart to ', FILE_NAME, '.ods');
book.WriteToFile(fn + '.ods', true);
WriteLn('Data saved with chart to ', fn, '.ods');
finally
book.Free;
end;

View File

@ -23,11 +23,16 @@ scatter_write_demo log-log
echo.
echo Scatter series and regression demo...
regressionchart_write_demo
regressionchart_write_demo rotated
echo.
echo StockSeries...
stock_write_demo hlc
stock_write_demo candlestick
echo.
echo StockSeries, rotated axes...
stock_write_demo hlc rotated
stock_write_demo candlestick rotated
echo.
echo StockSeries with volume...
stock_volume_write_demo hlc area
stock_volume_write_demo hlc bar
@ -36,3 +41,11 @@ stock_volume_write_demo candlestick area
stock_volume_write_demo candlestick bar
stock_volume_write_demo candlestick line
echo.
echo StockSeries with volume, rotated axes...
stock_volume_write_demo hlc area rotated
stock_volume_write_demo hlc bar rotated
stock_volume_write_demo hlc line rotated
stock_volume_write_demo candlestick area rotated
stock_volume_write_demo candlestick bar rotated
stock_volume_write_demo candlestick line rotated
echo.

View File

@ -20,15 +20,17 @@ var
fn: String;
candleStickMode: Boolean;
volumeMode: char;
rotated: Boolean;
procedure WriteHelp;
begin
WriteLn('SYNTAX: stock_volume_write_demo hlc|candlestick bar|area|line');
WriteLn('SYNTAX: stock_volume_write_demo hlc|candlestick bar|area|line [rotated]');
WriteLn(' hlc ........... Create high-low-close series');
WriteLn(' candlestick ... Create candle-stick series');
WriteLn(' area .......... Display volume as area series');
WriteLn(' bar ........... Display volume as bar series');
WriteLn(' line .......... Display volume as line series');
WriteLn(' rotated ....... (optional) rotated axes (date axis vertical)');
halt;
end;
@ -80,6 +82,8 @@ begin
else
WriteHelp;
end;
rotated := (ParamCount >= 3) and (lowercase(ParamStr(3)) = 'rotated');
if rotated then fn := fn + '-rotated';
end else
WriteHelp;
@ -109,6 +113,8 @@ begin
ch := book.AddChart(sheet, 2, 6, 150, 100);
// Chart properties
ch.RotatedAxes := rotated;
ch.Border.Style := clsNoLine;
ch.Legend.Border.Style := clsNoLine;
ch.Legend.Position := lpBottom;

View File

@ -18,12 +18,14 @@ var
d: TDate;
fn: String;
candlestickMode: Boolean;
rotated: Boolean;
procedure WriteHelp;
begin
WriteLn('SYNTAX: stock_write_demo hlc|candlestick');
WriteLn('SYNTAX: stock_write_demo hlc|candlestick [rotated]');
WriteLn(' hlc ........... Create high-low-close series');
WriteLn(' candlestick ... Create candle-stick series');
WriteLn(' rotated ....... optional: rotated axes (date vertical)');
halt;
end;
@ -55,6 +57,8 @@ begin
else
WriteHelp;
end;
rotated := (ParamCount >= 2) and (lowercase(ParamStr(2)) = 'rotated');
if rotated then fn := fn + '-rotated';
end else
WriteHelp;
@ -85,12 +89,13 @@ begin
// Chart properties
ch.Border.Style := clsNoLine;
ch.Legend.Border.Style := clsNoLine;
ch.RotatedAxes := rotated;
ch.XAxis.DateTime := true;
ch.XAxis.Title.Caption := 'Date';
ch.XAxis.MajorGridLines.Style := clsNoLine;
ch.XAxis.MinorGridLines.Style := clsNoLine;
ch.YAxis.Title.Caption := 'Stock price';
ch.YAxis.MajorGridLines.Style := clsSolid;
ch.YAxis.MajorGridLines.Style := clsSOLID;
ch.YAxis.MinorGridLines.Style := clsNoLine;
ch.YAxis.AutomaticMin := false;
ch.YAxis.AutomaticMax := false;

View File

@ -103,17 +103,26 @@ object Form1: TForm1
'../../../other/chart/pie.ods'
'../../../other/chart/radar.ods'
'../../../other/chart/regression.ods'
'../../../other/chart/regression-rotated.ods'
'../../../other/chart/scatter-lin.ods'
'../../../other/chart/scatter-log.ods'
'../../../other/chart/scatter-loglog.ods'
'../../../other/chart/stock-candlestick.ods'
'../../../other/chart/stock-candlestick-rotated.ods'
'../../../other/chart/stock-hlc.ods'
'../../../other/chart/stock-hlc-rotated.ods'
'../../../other/chart/stock-vol-candlestick-area.ods'
'../../../other/chart/stock-vol-candlestick-area-rotated.ods'
'../../../other/chart/stock-vol-candlestick-bars.ods'
'../../../other/chart/stock-vol-candlestick-bars-rotated.ods'
'../../../other/chart/stock-vol-candlestick-line.ods'
'../../../other/chart/stock-vol-candlestick-line-rotated.ods'
'../../../other/chart/stock-vol-hlc-area.ods'
'../../../other/chart/stock-vol-hlc-area-rotated.ods'
'../../../other/chart/stock-vol-hlc-bars.ods'
'../../../other/chart/stock-vol-hlc-bars-rotated.ods'
'../../../other/chart/stock-vol-hlc-line.ods'
'../../../other/chart/stock-vol-hlc-line-rotated.ods'
)
TabOrder = 0
OnCloseUp = ComboBox1CloseUp

View File

@ -2230,6 +2230,8 @@ begin
// style of regression line
UpdateChartPen(AWorkbookSeries.Chart, AWorkbookSeries.Regression.Line, ser.Pen);
ser.AxisIndexX := AChartSeries.AxisIndexX;
ser.AxisIndexY := AChartSeries.AxisIndexY;
FChart.AddSeries(ser);