diff --git a/components/fpspreadsheet/examples/other/chart/stock_volume_write_demo.lpi b/components/fpspreadsheet/examples/other/chart/stock_volume_write_demo.lpi
new file mode 100644
index 000000000..64c5abb83
--- /dev/null
+++ b/components/fpspreadsheet/examples/other/chart/stock_volume_write_demo.lpi
@@ -0,0 +1,68 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ -
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+
+
+
diff --git a/components/fpspreadsheet/examples/other/chart/stock_volume_write_demo.lpr b/components/fpspreadsheet/examples/other/chart/stock_volume_write_demo.lpr
new file mode 100644
index 000000000..ab08b705e
--- /dev/null
+++ b/components/fpspreadsheet/examples/other/chart/stock_volume_write_demo.lpr
@@ -0,0 +1,130 @@
+program stock_volume_write_demo;
+
+{$mode objfpc}{$H+}
+
+uses
+ SysUtils,
+ fpspreadsheet, fpstypes, fpsUtils, fpschart, xlsxooxml, fpsopendocument;
+
+const
+ FILE_NAME = 'stock-vol';
+ CANDLE_STICK = true; //false;
+
+var
+ book: TsWorkbook;
+ sheet: TsWorksheet;
+ ch: TsChart;
+ ser: TsStockSeries;
+ vser: TsChartSeries;
+ r: Integer;
+ d: TDate;
+ fn: String;
+
+ procedure WriteData(var ARow: Integer; var ADate: TDate; AVolume, AOpen, AHigh, ALow, AClose: Double);
+ begin
+ sheet.WriteDateTime(ARow, 0, ADate, nfShortDate);
+ sheet.WriteNumber (ARow, 1, AVolume, nfFixed, 0);
+ sheet.WriteNumber (ARow, 2, AOpen, nfFixed, 2);
+ sheet.WriteNumber (ARow, 3, AHigh, nfFixed, 2);
+ sheet.WriteNumber (ARow, 4, ALow, nfFixed, 2);
+ sheet.WriteNumber (ARow, 5, AClose, nfFixed, 2);
+ inc(ARow);
+ ADate := ADate + 1;
+ end;
+
+begin
+ book := TsWorkbook.Create;
+ try
+ // Worksheet
+ sheet := book.AddWorksheet('test');
+
+ // Enter data
+ sheet.WriteText (0, 0, 'My Company');
+ sheet.WriteFont (0, 0, '', 12, [fssBold], scBlack);
+ sheet.WriteText ( 2, 0, 'Date');
+ sheet.WriteText ( 2, 1, 'Volume');
+ sheet.WriteText ( 2, 2, 'Open');
+ sheet.WriteText ( 2, 3, 'High');
+ sheet.WriteText ( 2, 4, 'Low');
+ sheet.WriteText ( 2, 5, 'Close');
+ d := EncodeDate(2023, 3, 6);
+ r := 3; // Vol O H L C
+ WriteData(r, d, 100000, 100, 110, 95, 105);
+ WriteData(r, d, 90000, 107, 112, 101, 104);
+ WriteData(r, d, 120000, 108, 113, 100, 106);
+ WriteData(r, d, 110000, 109, 115, 99, 110);
+ WriteData(r, d, 95000, 110, 119, 103, 115);
+
+ // Create chart: left/top in cell D4, 150 mm x 100 mm
+ ch := book.AddChart(sheet, 2, 6, 150, 100);
+
+ // Chart properties
+ ch.Border.Style := clsNoLine;
+ ch.Legend.Border.Style := clsNoLine;
+ ch.Legend.Position := lpBottom;
+
+ 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.MinorGridLines.Style := clsNoLine;
+ ch.YAxis.AutomaticMin := false;
+ ch.YAxis.AutomaticMax := false;
+ ch.YAxis.Max := 120;
+ ch.YAxis.Min := 80;
+
+ ch.Y2Axis.Title.Caption := 'Volume';
+ ch.Y2Axis.MajorGridLines.Style := clsNoLine;
+ ch.Y2Axis.MinorGridLines.Style := clsNoLine;
+ ch.Y2Axis.AutomaticMax := false;
+ ch.Y2Axis.AutomaticMax := false;
+ ch.Y2Axis.Min := 0;
+ ch.Y2Axis.Max := 300000;
+
+ // Add stock series
+ ser := TsStockSeries.Create(ch);
+
+ // Stock series properties
+ ser.YAxis := alPrimary;
+ ser.CandleStick := CANDLE_STICK;
+ ser.CandleStickUpFill.Color := scGreen;
+ ser.CandlestickDownFill.Color := scRed;
+ ser.SetTitleAddr (0, 0);
+ if CANDLE_STICK 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);
+
+ // Bar 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');
+ }
+
+ book.WriteToFile(fn + '.ods', true);
+ WriteLn('Data saved with chart to ', fn, '.ods');
+ finally
+ book.Free;
+ end;
+end.
+
diff --git a/components/fpspreadsheet/examples/other/chart/write_demos.lpg b/components/fpspreadsheet/examples/other/chart/write_demos.lpg
index b7dcf5ee7..28e905a71 100644
--- a/components/fpspreadsheet/examples/other/chart/write_demos.lpg
+++ b/components/fpspreadsheet/examples/other/chart/write_demos.lpg
@@ -52,6 +52,11 @@
+
+
+
+
+
diff --git a/components/fpspreadsheet/source/common/fpsopendocumentchart.pas b/components/fpspreadsheet/source/common/fpsopendocumentchart.pas
index 295b9eeab..fd77fe88a 100644
--- a/components/fpspreadsheet/source/common/fpsopendocumentchart.pas
+++ b/components/fpspreadsheet/source/common/fpsopendocumentchart.pas
@@ -3447,8 +3447,8 @@ begin
// series
for i := 0 to AChart.Series.Count-1 do
- if AChart.GetChartType = ctStock then
- WriteChartStockSeries(AChartStream, AStyleStream, AchartIndent+2, AStyleIndent, AChart, i, AStyleID)
+ if AChart.Series[i].ChartType = ctStock then
+ WriteChartStockSeries(AChartStream, AStyleStream, AChartIndent+2, AStyleIndent, AChart, i, AStyleID)
else
WriteChartSeries(AChartStream, AStyleStream, AChartIndent+2, AStyleIndent, AChart, i, AStyleID);