fpspreadsheet: Beginning with rotated axes in chart link. Simplify generation of sample ods files.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@9084 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2023-12-14 22:50:59 +00:00
parent e51f7f3b29
commit af15ca0540
15 changed files with 302 additions and 350 deletions

View File

@ -33,7 +33,6 @@
<Unit>
<Filename Value="barchart_2axes_write_demo.lpr"/>
<IsPartOfProject Value="True"/>
<UnitName Value="barchart_write_demo"/>
</Unit>
</Units>
</ProjectOptions>
@ -52,11 +51,6 @@
<DebugInfoType Value="dsDwarf3"/>
</Debugging>
</Linking>
<Other>
<ConfigFile>
<WriteConfigFilePath Value=""/>
</ConfigFile>
</Other>
</CompilerOptions>
<Debugging>
<Exceptions>

View File

@ -1,19 +1,28 @@
program barchart_write_demo;
{.$DEFINE DARK_MODE}
program barchart_2axes_write_demo;
uses
SysUtils,
fpspreadsheet, fpstypes, fpsUtils, fpschart, xlsxooxml, fpsopendocument;
procedure WriteHelp;
begin
WriteLn('SYNTAX: barchart_2axes_write_demo [rotated]');
WriteLn(' (no argument) ..... vertical bars');
WriteLn(' rotated ........... hoizontal bars');
Halt;
end;
const
FILE_NAME = 'bars_2axes';
FILE_NAME = 'bars-2axes';
var
book: TsWorkbook;
sheet: TsWorksheet;
ch: TsChart;
ser: TsChartSeries;
fn: String;
begin
fn := FILE_NAME;
book := TsWorkbook.Create;
try
// worksheet
@ -40,15 +49,21 @@ begin
ch.Legend.Border.Style := clsNoLine;
ch.XAxis.Title.Caption := '';
ch.YAxis.Title.Caption := 'Count';
ch.YAxis.Title.Font.Color := $0075ea; //597bff;
ch.YAxis.AxisLine.Color := $0075ea; //597bff;
ch.YAxis.LabelFont.Color := $0075ea; //597bff;
ch.YAxis.Title.Font.Color := $0075ea;
ch.YAxis.AxisLine.Color := $0075ea;
ch.YAxis.LabelFont.Color := $0075ea;
ch.YAxis.MajorTicks := [];
ch.Y2Axis.Title.Caption := 'Volume';
ch.Y2Axis.Title.Font.Color := $b08359;
ch.Y2Axis.AxisLine.Color := $b08359;
ch.Y2Axis.LabelFont.Color := $b08359;
if (ParamCount >= 1) and (lowercase(ParamStr(1)) = 'rotated') then
begin
ch.RotatedAxes := true;
fn := fn + '-rotated';
end;
// Add 1st bar series ("Count")
ser := TsBarSeries.Create(ch);
ser.YAxis := alPrimary;
@ -56,7 +71,7 @@ begin
ser.SetLabelRange(3, 0, 8, 0);
ser.SetYRange(3, 1, 8, 1);
ser.Fill.Style := cfsSolid;
ser.Fill.Color := $0075ea; //597bff;
ser.Fill.Color := $0075ea;
ser.Line.Style := clsNoLine;
// Add 2nd bar series ("Volume")
@ -70,12 +85,12 @@ begin
ser.Line.Style := clsNoLine;
{
book.WriteToFile(FILE_NAME + '.xlsx', true); // Excel fails to open the file
WriteLn('Data saved with chart in ', FILENAME, '.xlsx');
book.WriteToFile(fn + '.xlsx', true); // Excel fails to open the file
WriteLn('Data saved with chart in ', fn, '.xlsx');
}
book.WriteToFile(FILE_NAME + '.ods', true);
WriteLn('Data saved with chart in ', FILE_NAME, '.ods');
book.WriteToFile(fn + '.ods', true);
WriteLn('Data saved with chart in ', fn, '.ods');
finally
book.Free;
end;

View File

@ -6,6 +6,14 @@ uses
SysUtils,
fpspreadsheet, fpstypes, fpsUtils, fpschart, xlsxooxml, fpsopendocument;
procedure WriteHelp;
begin
WriteLn('SYNTAX: barchart_write_demo [rotated]');
WriteLn(' (no argument) ..... vertical bars');
WriteLn(' rotated ........... hoizontal bars');
Halt;
end;
const
FILE_NAME = 'bars';
var
@ -13,7 +21,10 @@ var
sheet: TsWorksheet;
ch: TsChart;
ser: TsChartSeries;
fn: String;
begin
fn := FILE_NAME;
book := TsWorkbook.Create;
try
// worksheet
@ -44,6 +55,11 @@ begin
ch.YAxis.Title.Caption := 'Grade points';
ch.YAxis.AxisLine.Color := scSilver;
ch.YAxis.MajorTicks := [];
if (ParamCount >= 1) and (lowercase(ParamStr(1)) = 'rotated') then
begin
ch.RotatedAxes := true;
fn := fn + '-rotated';
end;
// Add 1st bar series ("Student 1")
ser := TsBarSeries.Create(ch);
@ -66,12 +82,12 @@ begin
ser.Fill.Color := scBlue;
{
book.WriteToFile(FILE_NAME + '.xlsx', true); // Excel fails to open the file
WriteLn('Data saved with chart in ', FILENAME, '.xlsx');
book.WriteToFile(fn + '.xlsx', true); // Excel fails to open the file
WriteLn('Data saved with chart in ', fn, '.xlsx');
}
book.WriteToFile(FILE_NAME + '.ods', true);
WriteLn('Data saved with chart in ', FILE_NAME, '.ods');
book.WriteToFile(fn + '.ods', true);
WriteLn('Data saved with chart in ', fn, '.ods');
finally
book.Free;
end;

View File

@ -0,0 +1,38 @@
@echo off
echo Generating chart demo files:
echo.
echo Bar series...
barchart_write_demo
barchart_write_demo rotated
barchart_2axes_write_demo
barchart_2axes_write_demo rotated
echo.
echo Bubble series...
bubblechart_write_demo
echo.
echo Pie series...
piechart_write_demo
echo.
echo Radar series...
radarchart_write_demo
echo.
echo Scatter series...
scatter_write_demo lin
scatter_write_demo log
scatter_write_demo log-log
echo.
echo Scatter series and regression demo...
regressionchart_write_demo
echo.
echo StockSeries...
stock_write_demo hlc
stock_write_demo candlestick
echo.
echo StockSeries with volume...
stock_volume_write_demo hlc area
stock_volume_write_demo hlc bar
stock_volume_write_demo hlc line
stock_volume_write_demo candlestick area
stock_volume_write_demo candlestick bar
stock_volume_write_demo candlestick line
echo.

View File

@ -1,73 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<ProjectOptions>
<Version Value="12"/>
<PathDelim Value="\"/>
<General>
<Flags>
<MainUnitHasCreateFormStatements Value="False"/>
<MainUnitHasTitleStatement Value="False"/>
<MainUnitHasScaledStatement Value="False"/>
</Flags>
<SessionStorage Value="InProjectDir"/>
<Title Value="scatter_log_write_demo"/>
<UseAppBundle Value="False"/>
<ResourceType Value="res"/>
</General>
<BuildModes>
<Item Name="Default" Default="True"/>
</BuildModes>
<PublishOptions>
<Version Value="2"/>
<UseFileFilters Value="True"/>
</PublishOptions>
<RunParams>
<FormatVersion Value="2"/>
</RunParams>
<RequiredPackages>
<Item>
<PackageName Value="laz_fpspreadsheet"/>
</Item>
</RequiredPackages>
<Units>
<Unit>
<Filename Value="scatter_log_write_demo.lpr"/>
<IsPartOfProject Value="True"/>
</Unit>
</Units>
</ProjectOptions>
<CompilerOptions>
<Version Value="11"/>
<PathDelim Value="\"/>
<Target>
<Filename Value="scatter_log_write_demo"/>
</Target>
<SearchPaths>
<IncludeFiles Value="$(ProjOutDir)"/>
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
</SearchPaths>
<Linking>
<Debugging>
<DebugInfoType Value="dsDwarf3"/>
</Debugging>
</Linking>
<Other>
<ConfigFile>
<WriteConfigFilePath Value=""/>
</ConfigFile>
</Other>
</CompilerOptions>
<Debugging>
<Exceptions>
<Item>
<Name Value="EAbort"/>
</Item>
<Item>
<Name Value="ECodetoolError"/>
</Item>
<Item>
<Name Value="EFOpenError"/>
</Item>
</Exceptions>
</Debugging>
</CONFIG>

View File

@ -1,65 +0,0 @@
program scatter_log_write_demo;
{$mode objfpc}{$H+}
uses
SysUtils,
fpspreadsheet, fpstypes, fpsUtils, fpschart, xlsxooxml, fpsopendocument;
const
FILE_NAME = 'scatter_log';
var
book: TsWorkbook;
sheet: TsWorksheet;
ch: TsChart;
ser: TsScatterSeries;
begin
book := TsWorkbook.Create;
try
// Worksheet
sheet := book.AddWorksheet('test');
// Enter data
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, 0.1); sheet.WriteFormula(3, 1, 'exp(A4)');
sheet.WriteNumber(4, 0, 0.8); sheet.WriteFormula(4, 1, 'exp(A5)');
sheet.WriteNumber(5, 0, 1.4); sheet.WriteFormula(5, 1, 'exp(A6)');
sheet.WriteNumber(6, 0, 2.6); sheet.WriteFormula(6, 1, 'exp(A7)');
sheet.WriteNumber(7, 0, 4.3); sheet.WriteFormula(7, 1, 'exp(A8)');
sheet.WriteNumber(8, 0, 5.9); sheet.WriteFormula(8, 1, 'exp(A9)');
sheet.WriteNumber(9, 0, 7.5); sheet.WriteFormula(9, 1, 'exp(A10)');
// Create chart: left/top in cell D4, 150 mm x 100 mm
ch := book.AddChart(sheet, 2, 3, 150, 100);
// Chart properties
ch.Border.Style := clsNoLine;
ch.Legend.Border.Style := clsNoLine;
ch.YAxis.Logarithmic := true;
// Add scatter series
ser := TsScatterSeries.Create(ch);
// Series properties
ser.SetTitleAddr(0, 0);
ser.SetXRange(3, 0, 9, 0);
ser.SetYRange(3, 1, 9, 1);
ser.ShowLines := true;
ser.ShowSymbols := true;
ser.Symbol := cssCircle;
{
book.WriteToFile(FILE_NAME + '.xlsx', true); // Excel fails to open the file
WriteLn('Data saved with chart to ', FILE_NAME, '.xlsx');
}
book.Options := book.Options + [boCalcBeforeSaving];
book.WriteToFile(FILE_NAME + '.ods', true);
WriteLn('Data saved with chart to ', FILE_NAME, '.ods');
finally
book.Free;
end;
end.

View File

@ -1,73 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<ProjectOptions>
<Version Value="12"/>
<PathDelim Value="\"/>
<General>
<Flags>
<MainUnitHasCreateFormStatements Value="False"/>
<MainUnitHasTitleStatement Value="False"/>
<MainUnitHasScaledStatement Value="False"/>
</Flags>
<SessionStorage Value="InProjectDir"/>
<Title Value="scatter_loglog_write_demo"/>
<UseAppBundle Value="False"/>
<ResourceType Value="res"/>
</General>
<BuildModes>
<Item Name="Default" Default="True"/>
</BuildModes>
<PublishOptions>
<Version Value="2"/>
<UseFileFilters Value="True"/>
</PublishOptions>
<RunParams>
<FormatVersion Value="2"/>
</RunParams>
<RequiredPackages>
<Item>
<PackageName Value="laz_fpspreadsheet"/>
</Item>
</RequiredPackages>
<Units>
<Unit>
<Filename Value="scatter_loglog_write_demo.lpr"/>
<IsPartOfProject Value="True"/>
</Unit>
</Units>
</ProjectOptions>
<CompilerOptions>
<Version Value="11"/>
<PathDelim Value="\"/>
<Target>
<Filename Value="scatter_loglog_write_demo"/>
</Target>
<SearchPaths>
<IncludeFiles Value="$(ProjOutDir)"/>
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
</SearchPaths>
<Linking>
<Debugging>
<DebugInfoType Value="dsDwarf3"/>
</Debugging>
</Linking>
<Other>
<ConfigFile>
<WriteConfigFilePath Value=""/>
</ConfigFile>
</Other>
</CompilerOptions>
<Debugging>
<Exceptions>
<Item>
<Name Value="EAbort"/>
</Item>
<Item>
<Name Value="ECodetoolError"/>
</Item>
<Item>
<Name Value="EFOpenError"/>
</Item>
</Exceptions>
</Debugging>
</CONFIG>

View File

@ -1,67 +0,0 @@
program scatter_loglog_write_demo;
{$mode objfpc}{$H+}
uses
SysUtils,
fpspreadsheet, fpstypes, fpsUtils, fpschart, xlsxooxml, fpsopendocument;
const
FILE_NAME = 'scatter_loglog';
var
book: TsWorkbook;
sheet: TsWorksheet;
ch: TsChart;
ser: TsScatterSeries;
begin
book := TsWorkbook.Create;
try
// Worksheet
sheet := book.AddWorksheet('test');
// Enter data
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, 0.1); sheet.WriteFormula(3, 1, 'A4^2');
sheet.WriteNumber(4, 0, 0.8); sheet.WriteFormula(4, 1, 'A5^2');
sheet.WriteNumber(5, 0, 1.9); sheet.WriteFormula(5, 1, 'A6^2');
sheet.WriteNumber(6, 0, 4.6); sheet.WriteFormula(6, 1, 'A7^2');
sheet.WriteNumber(7, 0, 8.3); sheet.WriteFormula(7, 1, 'A8^2');
sheet.WriteNumber(8, 0,15.9); sheet.WriteFormula(8, 1, 'A9^2');
sheet.WriteNumber(9, 0,25.6); sheet.WriteFormula(9, 1, 'A10^2');
sheet.WriteNumber(10,0,68.3); sheet.WriteFormula(10,1, 'A11^2');
// Create chart: left/top in cell D4, 150 mm x 100 mm
ch := book.AddChart(sheet, 2, 3, 150, 100);
// Chart properties
ch.Border.Style := clsNoLine;
ch.Legend.Border.Style := clsNoLine;
ch.XAxis.Logarithmic := true;
ch.YAxis.Logarithmic := true;
// Add scatter series
ser := TsScatterSeries.Create(ch);
// Series properties
ser.SetTitleAddr(0, 0);
ser.SetXRange(3, 0, 10, 0);
ser.SetYRange(3, 1, 10, 1);
ser.ShowLines := true;
ser.ShowSymbols := true;
ser.Symbol := cssCircle;
{
book.WriteToFile(FILE_NAME + '.xlsx', true); // Excel fails to open the file
WriteLn('Data saved with chart to ', FILE_NAME, '.xlsx');
}
book.Options := book.Options + [boCalcBeforeSaving];
book.WriteToFile(FILE_NAME + '.ods', true);
WriteLn('Data saved with chart to ', FILE_NAME, '.ods');
finally
book.Free;
end;
end.

View File

@ -51,11 +51,6 @@
<DebugInfoType Value="dsDwarf3"/>
</Debugging>
</Linking>
<Other>
<ConfigFile>
<WriteConfigFilePath Value=""/>
</ConfigFile>
</Other>
</CompilerOptions>
<Debugging>
<Exceptions>

View File

@ -6,6 +6,15 @@ uses
SysUtils,
fpspreadsheet, fpstypes, fpsUtils, fpschart, xlsxooxml, fpsopendocument;
procedure WriteHelp;
begin
WriteLn('SYNTAX: scatter_write_demo lin|log|loglog');
WriteLn(' lin ........... Both axes linear');
WriteLn(' log ........... y axis logarithmic');
WriteLn(' loglog ........ Both axes logarithmic');
halt;
end;
const
FILE_NAME = 'scatter';
var
@ -13,24 +22,74 @@ var
sheet: TsWorksheet;
ch: TsChart;
ser: TsScatterSeries;
fn: String;
mode: Integer; // 0=linear, 1=log, 2=log-log
begin
if ParamCount >= 1 then
begin
case lowercase(ParamStr(1)) of
'lin':
begin
mode := 0;
fn := FILE_NAME + '-lin';
end;
'log':
begin
mode := 1;
fn := FILE_NAME + '-log';
end;
'loglog', 'log-log':
begin
mode := 2;
fn := FILE_NAME + '-loglog';
end;
else
WriteHelp;
end;
end else
WriteHelp;
book := TsWorkbook.Create;
try
// Worksheet
sheet := book.AddWorksheet('test');
// Enter data
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, 0.1); sheet.WriteFormula( 3, 1, 'A4^2');
sheet.WriteNumber( 4, 0, 8.8); sheet.WriteFormula( 4, 1, 'A5^2');
sheet.WriteNumber( 5, 0,16.9); sheet.WriteFormula( 5, 1, 'A6^2');
sheet.WriteNumber( 6, 0,24.6); sheet.WriteFormula( 6, 1, 'A7^2');
sheet.WriteNumber( 7, 0,38.3); sheet.WriteFormula( 7, 1, 'A8^2');
sheet.WriteNumber( 8, 0,45.9); sheet.WriteFormula( 8, 1, 'A9^2');
sheet.WriteNumber( 9, 0,55.6); sheet.WriteFormula( 9, 1, 'A10^2');
sheet.WriteNumber(10, 0,68.3); sheet.WriteFormula(10, 1, 'A11^2');
sheet.WriteText(0, 0, 'Data');
sheet.WriteFont(0, 0, '', 12, [fssBold], scBlack);
sheet.WriteText ( 2, 0, 'x'); sheet.WriteText ( 2, 1, 'y');
case mode of
0: begin
sheet.WriteNumber( 3, 0, 0.1); sheet.WriteFormula( 3, 1, 'A4^2');
sheet.WriteNumber( 4, 0, 8.8); sheet.WriteFormula( 4, 1, 'A5^2');
sheet.WriteNumber( 5, 0, 16.9); sheet.WriteFormula( 5, 1, 'A6^2');
sheet.WriteNumber( 6, 0, 24.6); sheet.WriteFormula( 6, 1, 'A7^2');
sheet.WriteNumber( 7, 0, 38.3); sheet.WriteFormula( 7, 1, 'A8^2');
sheet.WriteNumber( 8, 0, 45.9); sheet.WriteFormula( 8, 1, 'A9^2');
sheet.WriteNumber( 9, 0, 55.6); sheet.WriteFormula( 9, 1, 'A10^2');
sheet.WriteNumber(10, 0, 68.3); sheet.WriteFormula(10, 1, 'A11^2');
end;
1: begin
sheet.WriteNumber(3, 0, 0.1); sheet.WriteFormula(3, 1, 'exp(A4)');
sheet.WriteNumber(4, 0, 0.8); sheet.WriteFormula(4, 1, 'exp(A5)');
sheet.WriteNumber(5, 0, 1.4); sheet.WriteFormula(5, 1, 'exp(A6)');
sheet.WriteNumber(6, 0, 2.6); sheet.WriteFormula(6, 1, 'exp(A7)');
sheet.WriteNumber(7, 0, 4.3); sheet.WriteFormula(7, 1, 'exp(A8)');
sheet.WriteNumber(8, 0, 5.9); sheet.WriteFormula(8, 1, 'exp(A9)');
sheet.WriteNumber(9, 0, 7.5); sheet.WriteFormula(9, 1, 'exp(A10)');
end;
2: begin
sheet.WriteNumber(3, 0, 0.1); sheet.WriteFormula(3, 1, 'A4^2');
sheet.WriteNumber(4, 0, 0.8); sheet.WriteFormula(4, 1, 'A5^2');
sheet.WriteNumber(5, 0, 1.9); sheet.WriteFormula(5, 1, 'A6^2');
sheet.WriteNumber(6, 0, 4.6); sheet.WriteFormula(6, 1, 'A7^2');
sheet.WriteNumber(7, 0, 8.3); sheet.WriteFormula(7, 1, 'A8^2');
sheet.WriteNumber(8, 0,15.9); sheet.WriteFormula(8, 1, 'A9^2');
sheet.WriteNumber(9, 0,25.6); sheet.WriteFormula(9, 1, 'A10^2');
sheet.WriteNumber(10,0,68.3); sheet.WriteFormula(10,1, 'A11^2');
end;
end;
// Create chart: left/top in cell D4, 150 mm x 100 mm
ch := book.AddChart(sheet, 2, 3, 150, 100);
@ -38,6 +97,17 @@ begin
// Chart properties
ch.Border.Style := clsNoLine;
ch.Legend.Border.Style := clsNoLine;
// Set up logarithmic axes if needed.
case mode of
0: ;
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;
// Add scatter series
ser := TsScatterSeries.Create(ch);
@ -56,8 +126,8 @@ begin
}
book.Options := book.Options + [boCalcBeforeSaving];
book.WriteToFile(FILE_NAME + '.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

@ -8,7 +8,6 @@ uses
const
FILE_NAME = 'stock-vol';
CANDLE_STICK = true; //false;
var
book: TsWorkbook;
@ -19,6 +18,19 @@ var
r: Integer;
d: TDate;
fn: String;
candleStickMode: Boolean;
volumeMode: char;
procedure WriteHelp;
begin
WriteLn('SYNTAX: stock_volume_write_demo hlc|candlestick bar|area|line');
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');
halt;
end;
procedure WriteData(var ARow: Integer; var ADate: TDate; AVolume, AOpen, AHigh, ALow, AClose: Double);
begin
@ -33,6 +45,44 @@ var
end;
begin
if ParamCount >= 2 then
begin
case lowercase(ParamStr(1)) of
'hlc':
begin
candleStickMode := false;
fn := FILE_NAME + '-hlc';
end;
'candlestick':
begin
candleStickMode := true;
fn := FILE_NAME + '-candlestick';
end;
else
WriteHelp;
end;
case lowercase(ParamStr(2)) of
'area':
begin
volumeMode := 'a';
fn := fn + '-area';
end;
'bar', 'bars':
begin
volumeMode := 'b';
fn := fn + '-bars';
end;
'line':
begin
volumeMode := 'l';
fn := fn + '-line';
end;
else
WriteHelp;
end;
end else
WriteHelp;
book := TsWorkbook.Create;
try
// Worksheet
@ -89,33 +139,29 @@ begin
// Stock series properties
ser.YAxis := alPrimary;
ser.CandleStick := CANDLE_STICK;
ser.CandleStick := candleStickMode;
ser.CandleStickUpFill.Color := scGreen;
ser.CandlestickDownFill.Color := scRed;
ser.SetTitleAddr (0, 0);
if CANDLE_STICK then ser.SetOpenRange (3, 2, 7, 2);
if candleStickMode then ser.SetOpenRange (3, 2, 7, 2);
ser.SetHighRange (3, 3, 7, 3);
ser.SetLowRange (3, 4, 7, 4);
ser.SetCloseRange(3, 5, 7, 5);
ser.SetLabelRange(3, 0, 7, 0);
// Add bar series for volume data
// (Activate one of the three next lines)
vser := TsBarSeries.Create(ch);
//vser := TsAreaSeries.Create(ch);
//vser := TsLineSeries.Create(ch);
// Add series for volume data, type depending on 2nd commandline argument
case volumeMode of
'a': vser := TsAreaSeries.Create(ch);
'b': vser := TsBarSeries.Create(ch);
'l': vser := TsLineSeries.Create(ch);
end;
// Bar series properties
// Volume series properties
vser.YAxis := alSecondary;
vser.SetLabelRange(3, 0, 7, 0);
vser.SetYRange (3, 1, 7, 1);
vser.SetTitleAddr (2, 1);
if CANDLE_STICK then
fn := FILE_NAME + '-candle'
else
fn := FILE_NAME + '-hlc';
{
book.WriteToFile(fn + '.xlsx', true); // Excel fails to open the file
WriteLn('Data saved with chart to ', fn, '.xlsx');

View File

@ -8,7 +8,6 @@ uses
const
FILE_NAME = 'stock';
CANDLE_STICK = false;
var
book: TsWorkbook;
@ -18,6 +17,15 @@ var
r: Integer;
d: TDate;
fn: String;
candlestickMode: Boolean;
procedure WriteHelp;
begin
WriteLn('SYNTAX: stock_write_demo hlc|candlestick');
WriteLn(' hlc ........... Create high-low-close series');
WriteLn(' candlestick ... Create candle-stick series');
halt;
end;
procedure WriteData(var ARow: Integer; var ADate: TDate; AOpen, AHigh, ALow, AClose: Double);
begin
@ -31,6 +39,25 @@ var
end;
begin
if ParamCount >= 1 then
begin
case lowercase(ParamStr(1)) of
'hlc':
begin
candleStickMode := false;
fn := FILE_NAME + '-hlc';
end;
'candlestick':
begin
candleStickMode := true;
fn := FILE_NAME + '-candlestick';
end;
else
WriteHelp;
end;
end else
WriteHelp;
book := TsWorkbook.Create;
try
// Worksheet
@ -74,22 +101,17 @@ begin
ser := TsStockSeries.Create(ch);
// Series properties
ser.CandleStick := CANDLE_STICK;
ser.CandleStick := candleStickMode;
ser.CandleStickUpFill.Color := scGreen;
ser.CandlestickDownFill.Color := scRed;
ser.SetTitleAddr (0, 0);
if CANDLE_STICK then ser.SetOpenRange (3, 1, 7, 1);
if candleStickMode then ser.SetOpenRange (3, 1, 7, 1);
ser.SetHighRange (3, 2, 7, 2);
ser.SetLowRange (3, 3, 7, 3);
ser.SetCloseRange(3, 4, 7, 4);
ser.SetXRange (3, 0, 7, 0);
ser.SetLabelRange(3, 0, 7, 0);
if CANDLE_STICK then
fn := FILE_NAME + '-candle'
else
fn := FILE_NAME + '-hlc';
{
book.WriteToFile(fn + '.xlsx', true); // Excel fails to open the file
WriteLn('Data saved with chart to ', fn, '.xlsx');

View File

@ -1,7 +1,7 @@
object Form1: TForm1
Left = 314
Left = 467
Height = 527
Top = 130
Top = 160
Width = 1351
Caption = 'Form1'
ClientHeight = 527
@ -22,6 +22,7 @@ object Form1: TForm1
WorkbookSource = sWorkbookSource1
Align = alLeft
AutoAdvance = aaDown
Color = clWhite
DefaultColWidth = 64
DefaultRowHeight = 22
Options = [goFixedVertLine, goFixedHorzLine, goVertLine, goHorzLine, goRangeSelect, goRowSizing, goColSizing, goEditing, goSmoothScroll]
@ -93,18 +94,25 @@ object Form1: TForm1
DropDownCount = 32
ItemHeight = 15
Items.Strings = (
'../../../other/chart/area.ods'
'../../../other/chart/bars.ods'
'../../../other/chart/bars_2axes.ods'
'../../../other/chart/bars-rotated.ods'
'../../../other/chart/bars-2axes.ods'
'../../../other/chart/bars-2axes-rotated.ods'
'../../../other/chart/bubble.ods'
'../../../other/chart/pie.ods'
'../../../other/chart/radar.ods'
'../../../other/chart/regression.ods'
'../../../other/chart/scatter.ods'
'../../../other/chart/scatter_log.ods'
'../../../other/chart/scatter_loglog.ods'
'../../../other/chart/stock-candle.ods'
'../../../other/chart/scatter-lin.ods'
'../../../other/chart/scatter-log.ods'
'../../../other/chart/scatter-loglog.ods'
'../../../other/chart/stock-candlestick.ods'
'../../../other/chart/stock-hlc.ods'
'../../../other/chart/stock-vol-candlestick-area.ods'
'../../../other/chart/stock-vol-candlestick-bars.ods'
'../../../other/chart/stock-vol-candlestick-line.ods'
'../../../other/chart/stock-vol-hlc-area.ods'
'../../../other/chart/stock-vol-hlc-bars.ods'
'../../../other/chart/stock-vol-hlc-line.ods'
)
TabOrder = 0
OnCloseUp = ComboBox1CloseUp

View File

@ -1050,15 +1050,23 @@ begin
case nodeName of
'style:chart-properties':
begin
// Stacked
s := GetAttrValue(AStyleNode, 'chart:stacked');
if s = 'true' then
AChart.StackMode := csmStacked;
// Stacked as percentage
s := GetAttrValue(AStyleNode, 'chart:percentage');
if s = 'true' then
AChart.StackMode := csmStackedPercentage;
// Horizontal bars
s := GetAttrValue(AStyleNode, 'chart:vertical');
if s = 'true' then
AChart.RotatedAxes := true;
// Pie series start angle
s := GetAttrValue(AStyleNode, 'chart:angle-offset');
if s <> '' then
FPieSeriesStartAngle := StrToInt(s);
// Stockseries candlestick mode
s := GetAttrValue(AStyleNode, 'chart:japanese-candle-stick');
if (s <> '') and (FStockSeries <> nil) then
FStockSeries.CandleStick := true;

View File

@ -1022,18 +1022,30 @@ begin
end;
function TsWorkbookChartLink.ActiveChartSeries(ASeries: TsChartSeries): TChartSeries;
type
TAxisType = (xAx, yAx);
const
AXIS_ALIGNMENT: array[boolean, TsChartAxisLink, TAxisType] of TChartAxisAlignment = (
( (calBottom, calLeft), // not rotated - primary
(calTop, calRight) ), // not rotated - secondary
( (calLeft, calBottom), // rotated - primary
(calRight, calTop) ) // rotated - secondary
);
var
stackable: Boolean;
firstSeries: TChartSeries;
ch: TsChart;
src: TsWorkbookChartSource;
calcSrc: TCalculatedChartSource;
style: TChartStyle;
axAlign: TChartAxisAlignment;
begin
if FChart.Series.Count > 0 then
firstSeries := FChart.Series[0] as TChartSeries
else
firstSeries := nil;
ch := ASeries.Chart;
stackable := IsStackable(ASeries);
if stackable and (firstSeries <> nil) then
@ -1145,6 +1157,11 @@ begin
end;
// Assign series index to axis for primary and secondary axes support
axAlign := AXIS_ALIGNMENT[ch.RotatedAxes, ASeries.XAxis, xAx];
Result.AxisIndexX := FChart.AxisList.GetAxisByAlign(axAlign).Index;
axAlign := AXIS_ALIGNMENT[ch.RotatedAxes, ASeries.YAxis, yAx];
Result.AxisIndexY := FChart.AxisList.GetAxisByAlign(axAlign).Index;
{
case ASeries.XAxis of
alPrimary:
Result.AxisIndexX := FChart.AxisList.GetAxisByAlign(calBottom).Index;
@ -1157,6 +1174,7 @@ begin
alSecondary:
Result.AxisIndexY := FChart.AxisList.GetAxisByAlign(calRight).Index;
end;
}
if stackable then
begin
@ -1840,13 +1858,13 @@ begin
logTransf.Enabled := AWorkbookAxis.Logarithmic;
if AWorkbookAxis.Logarithmic then
begin
axis.Intervals.Options := axis.Intervals.Options + [aipGraphCoords];
axis.Intervals.Options := axis.Intervals.Options + [aipGraphCoords{$IF LCL_FullVersion >= 3990000}, aipInteger{$IFEND}];
axis.Intervals.MaxLength := 150;
axis.Intervals.MinLength := 30;
axis.Intervals.Tolerance := 30;
end else
begin
axis.Intervals.Options := axis.Intervals.Options - [aipGraphCoords];
axis.Intervals.Options := axis.Intervals.Options - [aipGraphCoords{$IF LCL_FullVersion >= 3990000}, aipInteger{$IFEND}];
axis.Intervals.MaxLength := 100;
axis.Intervals.MinLength := 20;
axis.Intervals.Tolerance := 0;