fpspreadsheet: Add demo for stacked & rotated bar series.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@9095 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2023-12-19 13:24:39 +00:00
parent 41fda1fbfb
commit 8b8a73d887
5 changed files with 184 additions and 1 deletions

View File

@ -0,0 +1,68 @@
<?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="barchart_stacked_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="barchart_stacked_write_demo.lpr"/>
<IsPartOfProject Value="True"/>
</Unit>
</Units>
</ProjectOptions>
<CompilerOptions>
<Version Value="11"/>
<PathDelim Value="\"/>
<Target>
<Filename Value="barchart_stacked_write_demo"/>
</Target>
<SearchPaths>
<IncludeFiles Value="$(ProjOutDir)"/>
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
</SearchPaths>
<Linking>
<Debugging>
<DebugInfoType Value="dsDwarf3"/>
</Debugging>
</Linking>
</CompilerOptions>
<Debugging>
<Exceptions>
<Item>
<Name Value="EAbort"/>
</Item>
<Item>
<Name Value="ECodetoolError"/>
</Item>
<Item>
<Name Value="EFOpenError"/>
</Item>
</Exceptions>
</Debugging>
</CONFIG>

View File

@ -0,0 +1,107 @@
program barchart_stacked_write_demo;
{.$DEFINE DARK_MODE}
uses
SysUtils,
fpspreadsheet, fpstypes, fpsUtils, fpschart, xlsxooxml, fpsopendocument;
procedure WriteHelp;
begin
WriteLn('SYNTAX: barchart_stacked_write_demo [rotated]');
WriteLn(' rotated ........... hoizontal bars, otherwise: vertical bar');
WriteLn(' percentage ........ stacked percentage, otherwise: normal stacking');
Halt;
end;
const
FILE_NAME = 'bars-stacked';
var
book: TsWorkbook;
sheet: TsWorksheet;
ch: TsChart;
ser: TsChartSeries;
fn: String;
i: Integer;
rotated: Boolean = false;
stackedPercentage: Boolean = false;
begin
if (ParamCount = 1) and ((ParamStr(1) = '--help') or (ParamStr(1) = '-h')) then
WriteHelp;
fn := FILE_NAME;
for i := 1 to ParamCount do
case lowercase(ParamStr(i)) of
'rotated':
begin
rotated := true;
fn := fn + '-rotated';
end;
'percentage':
begin
stackedPercentage := true;
fn := fn + '-percentage';
end;
end;
book := TsWorkbook.Create;
try
// worksheet
sheet := book.AddWorksheet('bar_series_stacked');
// Enter data
sheet.WriteText( 0, 0, 'Stacked bar series demo');
sheet.WriteFont( 0, 0, '', 12, [fssBold], scBlack);
sheet.WriteText( 2, 0, 'Quarters'); sheet.WriteText ( 2, 1, 'Product A'); sheet.WriteText ( 2, 2, 'Product B');
sheet.WriteText( 3, 0, 'Q1/2022'); sheet.WriteNumber( 3, 1, 125); sheet.WriteNumber( 3, 2, 207);
sheet.WriteText( 4, 0, 'Q2/2022'); sheet.WriteNumber( 4, 1, 176); sheet.WriteNumber( 4, 2, 199);
sheet.WriteText( 5, 0, 'Q3/2022'); sheet.WriteNumber( 5, 1, 264); sheet.WriteNumber( 5, 2, 194);
sheet.WriteText( 6, 0, 'Q4/2022'); sheet.WriteNumber( 6, 1, 311); sheet.WriteNumber( 6, 2, 183);
// Create chart: left/top in cell D4, 160 mm x 100 mm
ch := book.AddChart(sheet, 2, 3, 120, 100);
// Chart properties
if stackedPercentage then
ch.StackMode :=csmStackedPercentage
else
ch.StackMode := csmStacked;
if rotated then
ch.RotatedAxes := rotated;
ch.Border.Style := clsNoLine;
ch.Title.Caption := 'Product Sales';
ch.Title.Font.Style := [fssBold];
ch.Legend.Border.Style := clsNoLine;
ch.XAxis.Title.Caption := '';
ch.YAxis.Title.Caption := 'Quarter';
ch.YAxis.AxisLine.Color := scSilver;
ch.YAxis.MajorTicks := [];
// Add 1st bar series ("Product A")
ser := TsBarSeries.Create(ch);
ser.SetTitleAddr(2, 1);
ser.SetLabelRange(3, 0, 6, 0);
ser.SetYRange(3, 1, 6, 1);
ser.Fill.Color := $3810F3;
ser.Line.Style := clsNoLine;
// Add 2nd bar series ("Product B")
ser := TsBarSeries.Create(ch);
ser.SetTitleAddr(2, 2);
ser.SetLabelRange(3, 0, 6, 0);
ser.SetYRange(3, 2, 6, 2);
ser.Fill.Color := $4200A8;
ser.Line.Style := clsNoLine;
{
book.WriteToFile(fn + '.xlsx', true); // Excel fails to open the file
WriteLn('Data saved with chart in ', fn, '.xlsx');
}
book.WriteToFile(fn + '.ods', true);
WriteLn('Data saved with chart in ', fn, '.ods');
finally
book.Free;
end;
end.

View File

@ -62,7 +62,7 @@ begin
ser.Regression.Line.Color := scRed; ser.Regression.Line.Color := scRed;
ser.Regression.Line.Style := clsDash; ser.Regression.Line.Style := clsDash;
ser.Regression.ForceYIntercept := true; // not used by logarithmic, power ser.Regression.ForceYIntercept := true; // not used by logarithmic, power
ser.Regression.YInterceptValue := 1.0; // dto. ser.Regression.YInterceptValue := 10.0; // dto.
ser.Regression.PolynomialDegree := 2; ser.Regression.PolynomialDegree := 2;
ser.Regression.DisplayEquation := true; ser.Regression.DisplayEquation := true;
ser.Regression.DisplayRSquare := true; ser.Regression.DisplayRSquare := true;

View File

@ -6,6 +6,10 @@ barchart_write_demo
barchart_write_demo rotated barchart_write_demo rotated
barchart_2axes_write_demo barchart_2axes_write_demo
barchart_2axes_write_demo rotated barchart_2axes_write_demo rotated
barchart_stacked_write_demo
barchart_stacked_write_demo rotated
barchart_stacked_write_demo percentage
barchart_stacked_write_demo percentage rotated
echo. echo.
echo Bubble series... echo Bubble series...
bubblechart_write_demo bubblechart_write_demo

View File

@ -97,6 +97,10 @@ object Form1: TForm1
Items.Strings = ( Items.Strings = (
'../../../other/chart/bars.ods' '../../../other/chart/bars.ods'
'../../../other/chart/bars-rotated.ods' '../../../other/chart/bars-rotated.ods'
'../../../other/chart/bars-stacked.ods'
'../../../other/chart/bars-stacked-rotated.ods'
'../../../other/chart/bars-stacked-percentage.ods'
'../../../other/chart/bars-stacked-percentage-rotated.ods'
'../../../other/chart/bars-2axes.ods' '../../../other/chart/bars-2axes.ods'
'../../../other/chart/bars-2axes-rotated.ods' '../../../other/chart/bars-2axes-rotated.ods'
'../../../other/chart/bubble.ods' '../../../other/chart/bubble.ods'