diff --git a/components/fpspreadsheet/examples/other/chart/barchart_write_demo.lpr b/components/fpspreadsheet/examples/other/chart/barchart_write_demo.lpr index 2e622801e..fafbf70d1 100644 --- a/components/fpspreadsheet/examples/other/chart/barchart_write_demo.lpr +++ b/components/fpspreadsheet/examples/other/chart/barchart_write_demo.lpr @@ -5,16 +5,19 @@ program barchart_write_demo; uses SysUtils, fpspreadsheet, fpstypes, fpsUtils, fpschart, xlsxooxml, fpsopendocument; + +const + FILE_NAME = 'bars'; var - b: TsWorkbook; + book: TsWorkbook; sheet: TsWorksheet; ch: TsChart; ser: TsChartSeries; begin - b := TsWorkbook.Create; + book := TsWorkbook.Create; try // worksheet - sheet := b.AddWorksheet('bar_series'); + sheet := book.AddWorksheet('bar_series'); // Enter data sheet.WriteText( 0, 0, 'School Grades'); @@ -30,15 +33,15 @@ begin sheet.WriteText(10, 0, 'Computer'); sheet.WriteNumber(10, 1, 16); sheet.WriteNumber(10, 2, 18); // Create chart: left/top in cell D4, 160 mm x 100 mm - ch := b.AddChart(sheet, 2, 3, 120, 100); + ch := book.AddChart(sheet, 2, 3, 120, 100); // Chart properties ch.Border.Style := clsNoLine; ch.Title.Caption := 'School Grades'; ch.Title.Font.Style := [fssBold]; ch.Legend.Border.Style := clsNoLine; - ch.XAxis.Caption := ''; - ch.YAxis.Caption := ''; + ch.XAxis.Title.Caption := ''; + ch.YAxis.Title.Caption := 'Grade points'; ch.YAxis.AxisLine.Color := scSilver; ch.YAxis.MajorTicks := []; @@ -62,10 +65,15 @@ begin ser.Fill.Hatch := ch.Hatches.AddHatch('Forward', chsSingle, scWhite, 1.5, 45, true); ser.Fill.Color := scBlue; -// b.WriteToFile('bars.xlsx', true); // Excel fails to open the file - b.WriteToFile('bars.ods', true); + { + book.WriteToFile(FILE_NAME + '.xlsx', true); // Excel fails to open the file + WriteLn('Data saved with chart in ', FILENAME, '.xlsx'); + } + + book.WriteToFile(FILE_NAME + '.ods', true); + WriteLn('Data saved with chart in ', FILE_NAME, '.ods'); finally - b.Free; + book.Free; end; end. diff --git a/components/fpspreadsheet/examples/other/chart/piechart_write_demo.lpr b/components/fpspreadsheet/examples/other/chart/piechart_write_demo.lpr index 6b48dd844..6ce9b85f9 100644 --- a/components/fpspreadsheet/examples/other/chart/piechart_write_demo.lpr +++ b/components/fpspreadsheet/examples/other/chart/piechart_write_demo.lpr @@ -5,16 +5,19 @@ program piechart_write_demo; uses SysUtils, fpspreadsheet, fpstypes, fpsUtils, fpschart, xlsxooxml, fpsopendocument; + +const + FILE_NAME = 'world-population'; var - b: TsWorkbook; + book: TsWorkbook; sheet: TsWorksheet; ch: TsChart; ser: TsChartSeries; begin - b := TsWorkbook.Create; + book := TsWorkbook.Create; try // worksheet - sheet := b.AddWorksheet('pie_series'); + sheet := book.AddWorksheet('pie_series'); // Enter data sheet.WriteText(0, 0, 'World population'); @@ -29,7 +32,7 @@ begin sheet.WriteText(8, 0, 'Oceania'); sheet.WriteNumber(8, 1, 42); // sheet.WriteChartColor(8, 2, $FF8080); // Create chart: left/top in cell D4, 120 mm x 100 mm - ch := b.AddChart(sheet, 2, 3, 120, 100); + ch := book.AddChart(sheet, 2, 3, 120, 100); // Chart properties ch.Border.Style := clsNoLine; @@ -52,10 +55,15 @@ begin ser.LabelFormat := '#,##0'; //ser.SetFillColorRange(4, 2, 8, 2); - b.WriteToFile('world-population.xlsx', true); // Excel fails to open the file - b.WriteToFile('world-population.ods', true); + { + book.WriteToFile(FILE_NAME+'.xlsx', true); // Excel fails to open the file + WriteLn('Data saved with chart in ', FILE_NAME, '.xlsx'); + } + + book.WriteToFile(FILE_NAME + '.ods', true); + WriteLn('Data saved with chart in ', FILE_NAME, '.ods'); finally - b.Free; + book.Free; end; end. diff --git a/components/fpspreadsheet/examples/other/chart/radarchart_write_demo.lpr b/components/fpspreadsheet/examples/other/chart/radarchart_write_demo.lpr index cf4371863..c3bf7d846 100644 --- a/components/fpspreadsheet/examples/other/chart/radarchart_write_demo.lpr +++ b/components/fpspreadsheet/examples/other/chart/radarchart_write_demo.lpr @@ -5,16 +5,19 @@ program radarchart_write_demo; uses SysUtils, fpspreadsheet, fpstypes, fpsUtils, fpschart, xlsxooxml, fpsopendocument; + +const + FILE_NAME = 'school-grades'; var - b: TsWorkbook; + book: TsWorkbook; sheet: TsWorksheet; ch: TsChart; ser: TsChartSeries; begin - b := TsWorkbook.Create; + book := TsWorkbook.Create; try // worksheet - sheet := b.AddWorksheet('radar_series'); + sheet := book.AddWorksheet('radar_series'); // Enter data sheet.WriteText( 0, 0, 'School Grades'); @@ -30,15 +33,15 @@ begin sheet.WriteText(10, 0, 'Computer'); sheet.WriteNumber(10, 1, 16); sheet.WriteNumber(10, 2, 18); // Create chart: left/top in cell D4, 160 mm x 100 mm - ch := b.AddChart(sheet, 2, 3, 120, 100); + ch := book.AddChart(sheet, 2, 3, 120, 100); // Chart properties ch.Border.Style := clsNoLine; ch.Title.Caption := 'School Grades'; ch.Title.Font.Style := [fssBold]; ch.Legend.Border.Style := clsNoLine; - ch.XAxis.Caption := ''; - ch.YAxis.Caption := ''; + ch.XAxis.Title.Caption := ''; + ch.YAxis.Title.Caption := ''; ch.YAxis.AxisLine.Color := scSilver; ch.YAxis.MajorTicks := []; @@ -60,10 +63,15 @@ begin ser.Fill.Color := scBlue; ser.Fill.Transparency := 0.35; - b.WriteToFile('school-grades.xlsx', true); // Excel fails to open the file - b.WriteToFile('school-grades.ods', true); + { + book.WriteToFile(FILE_NAME + '.xlsx', true); // Excel fails to open the file + WriteLn('Data saved with chart in ', FILE_NAME, '.xlsx'); + } + + book.WriteToFile(FILE_NAME + '.ods', true); + WriteLn('Data saved with chart in ', FILE_NAME, '.ods'); finally - b.Free; + book.Free; end; end. diff --git a/components/fpspreadsheet/examples/other/chart/read_chart_demo.lpr b/components/fpspreadsheet/examples/other/chart/read_chart_demo.lpr index d83035fd7..85c1a77c2 100644 --- a/components/fpspreadsheet/examples/other/chart/read_chart_demo.lpr +++ b/components/fpspreadsheet/examples/other/chart/read_chart_demo.lpr @@ -5,21 +5,23 @@ uses fpSpreadsheet, fpsTypes, fpsChart, fpsOpenDocument; const -// FILE_NAME = 'test.ods'; - FILE_NAME = 'area.ods'; + FILE_NAME = 'test.ods'; +// FILE_NAME = 'area.ods'; var - b: TsWorkbook; + book: TsWorkbook; sheet: TsWorksheet; chart: TsChart; i, j: Integer; begin - b := TsWorkbook.Create; + book := TsWorkbook.Create; try - b.ReadFromFile(FILE_NAME); - for i := 0 to b.GetChartCount-1 do + book.ReadFromFile(FILE_NAME); + for i := 0 to book.GetChartCount-1 do begin - chart := b.GetChartByIndex(i); - sheet := b.GetWorksheetByIndex(chart.SheetIndex); + chart := book.GetChartByIndex(i); + sheet := book.GetWorksheetByIndex(chart.SheetIndex); + + WriteLn('--------------------------------------------------------------------------------'); WriteLn('Chart "', chart.Name, '":'); WriteLn(' Worksheet "', sheet.Name, '", ', 'row:', chart.Row, ' (+',chart.OffsetY:0:0, 'mm) ', @@ -117,10 +119,70 @@ begin WriteLn(' Font: "', chart.Subtitle.Font.FontName, '" Size:', chart.Subtitle.Font.Size:0:0, ' Style:', SetToString(PTypeInfo(TypeInfo(TsFontStyles)), integer(chart.Subtitle.Font.Style), True), ' Color:', IntToHex(chart.Subtitle.Font.Color, 6)); + + WriteLn; + WriteLn(' CHART X AXIS'); + WriteLn(' VISIBLE:', chart.YAxis.Visible); + WriteLn(' TITLE: Caption: "', StringReplace(chart.XAxis.Title.Caption, FPS_LINE_ENDING, '\n', [rfReplaceAll]), '"', + ' Visible: ', chart.XAxis.Title.Visible, + ' Rotation: ', chart.XAxis.Title.RotationAngle, + ' Font: "', chart.XAxis.Title.Font.FontName, '" Size:', chart.XAxis.Title.Font.Size:0:0, + ' Style:', SetToString(PTypeInfo(TypeInfo(TsFontStyles)), integer(chart.XAxis.Title.Font.Style), True), + ' Color:', IntToHex(chart.XAxis.Title.Font.Color, 6)); + WriteLn(' RANGE: AutomaticMin:', chart.XAxis.AutomaticMin, ' Minimum: ', chart.XAxis.Min:0:3, + ' AutomaticMax:', chart.XAxis.AutomaticMax, ' Maximum: ', chart.XAxis.Max:0:3); + WriteLn(' POSITION: ', GetEnumName(TypeInfo(TsChartAxisPosition), ord(chart.XAXis.Position)), + ' Value:', chart.XAxis.PositionValue:0:3); + WriteLn(' AXIS TICKS: Major interval:', chart.XAxis.MajorInterval:0:2, + ' Major ticks:', SetToString(PTypeInfo(TypeInfo(TsChartAxisTicks)), integer(chart.XAxis.MajorTicks), True), + ' Minor count:', chart.XAxis.MinorCount, + ' Minor ticks:', SetToString(PTypeInfo(TypeInfo(TsChartAxisTicks)), integer(chart.XAxis.MinorTicks), True)); + WriteLn(' AXIS LINE: Style:', chart.XAxis.AxisLine.Style, + ' Width:', chart.XAxis.AxisLine.Width:0:0, 'mm', + ' Color:', IntToHex(chart.XAxis.AxisLine.Color, 6), + ' Transparency:', chart.XAxis.AxisLine.Transparency:0:2); + WriteLn(' MAJOR GRID: Style:', chart.XAxis.MajorGridLines.Style, + ' Width:', chart.XAxis.MajorGridLines.Width:0:0, 'mm', + ' Color:', IntToHex(chart.XAxis.MajorGridLines.Color, 6), + ' Transparency:', chart.XAxis.MajorGridLines.Transparency:0:2); + WriteLn(' MINOR GRID: Style:', chart.XAxis.MinorGridLines.Style, + ' Width:', chart.XAxis.MinorGridLines.Width:0:0, 'mm', + ' Color:', IntToHex(chart.XAxis.MinorGridLines.Color, 6), + ' Transparency:', chart.XAxis.MinorGridLines.Transparency:0:2); + + WriteLn; + WriteLn(' CHART Y AXIS:'); + WriteLn(' VISIBLE:', chart.YAxis.Visible); + WriteLn(' TITLE: Caption: "', StringReplace(chart.YAxis.Title.Caption, FPS_LINE_ENDING, '\n', [rfReplaceAll]), '"', + ' Visible: ', chart.YAxis.Title.Visible, + ' Rotation: ', chart.YAxis.Title.RotationAngle, + ' Font: "', chart.YAxis.Title.Font.FontName, '" Size:', chart.YAxis.Title.Font.Size:0:0, + ' Style:', SetToString(PTypeInfo(TypeInfo(TsFontStyles)), integer(chart.YAxis.Title.Font.Style), True), + ' Color:', IntToHex(chart.YAxis.Title.Font.Color, 6)); + WriteLn(' RANGE: AutomaticMin:', chart.YAxis.AutomaticMin, ' Minimum: ', chart.YAxis.Min:0:3, + ' AutomaticMax:', chart.YAxis.AutomaticMax, ' Maximum: ', chart.YAxis.Max:0:3); + WriteLn(' POSITION: ', GetEnumName(TypeInfo(TsChartAxisPosition), ord(chart.YAXis.Position)), + ' Value:', chart.YAxis.PositionValue:0:3); + WriteLn(' AXIS TICKS: Major interval:', chart.YAxis.MajorInterval:0:2, + ' Major ticks:', SetToString(PTypeInfo(TypeInfo(TsChartAxisTicks)), integer(chart.YAxis.MajorTicks), True), + ' Minor count:', chart.YAxis.MinorCount, + ' Minor ticks:', SetToString(PTypeInfo(TypeInfo(TsChartAxisTicks)), integer(chart.YAxis.MinorTicks), True)); + WriteLn(' AXIS LINE: Style:', chart.YAxis.AxisLine.Style, + ' Width:', chart.YAxis.AxisLine.Width:0:0, 'mm', + ' Color:', IntToHex(chart.YAxis.AxisLine.Color, 6), + ' Transparency:', chart.YAxis.AxisLine.Transparency:0:2); + WriteLn(' MAJOR GRID: Style:', chart.YAxis.MajorGridLines.Style, + ' Width:', chart.YAxis.MajorGridLines.Width:0:0, 'mm', + ' Color:', IntToHex(chart.YAxis.MajorGridLines.Color, 6), + ' Transparency:', chart.YAxis.MajorGridLines.Transparency:0:2); + WriteLn(' MINOR GRID: Style:', chart.YAxis.MinorGridLines.Style, + ' Width:', chart.YAxis.MinorGridLines.Width:0:0, 'mm', + ' Color:', IntToHex(chart.YAxis.MinorGridLines.Color, 6), + ' Transparency:', chart.YAxis.MinorGridLines.Transparency:0:2); end; finally - b.Free; + book.Free; end; WriteLn; diff --git a/components/fpspreadsheet/examples/other/chart/regressionchart_write_demo.lpr b/components/fpspreadsheet/examples/other/chart/regressionchart_write_demo.lpr index 6f25dfc78..018b0fa91 100644 --- a/components/fpspreadsheet/examples/other/chart/regressionchart_write_demo.lpr +++ b/components/fpspreadsheet/examples/other/chart/regressionchart_write_demo.lpr @@ -5,16 +5,19 @@ program regressionchart_write_demo; uses SysUtils, fpspreadsheet, fpstypes, fpsUtils, fpschart, xlsxooxml, fpsopendocument; + +const + FILE_NAME = 'regression'; var - b: TsWorkbook; + book: TsWorkbook; sheet: TsWorksheet; ch: TsChart; ser: TsScatterSeries; begin - b := TsWorkbook.Create; + book := TsWorkbook.Create; try // worksheet - sheet := b.AddWorksheet('regression_test'); + sheet := book.AddWorksheet('regression_test'); // Enter data sheet.WriteText(0, 0, 'Data'); @@ -28,7 +31,7 @@ begin sheet.WriteNumber(8, 0, 6.8); sheet.WriteNumber(8, 1, 7.1); // sheet.WriteChartColor(8, 2, $FF8080); // Create chart: left/top in cell D4, 120 mm x 100 mm - ch := b.AddChart(sheet, 2, 3, 120, 100); + ch := book.AddChart(sheet, 2, 3, 120, 100); // Chart properties ch.Border.Style := clsNoLine; @@ -65,10 +68,15 @@ begin //ser.Regression.Equation.Top := 5; //ser.Regression.Equation.Left := 5; - b.WriteToFile('regression.xlsx', true); // Excel fails to open the file - b.WriteToFile('regression.ods', true); + { + book.WriteToFile(FILE_NAME + '.xlsx', true); // Excel fails to open the file + WriteLn('Data saved with chart to ', FILE_NAME, '.xlsx'); + } + + book.WriteToFile('regression.ods', true); + WriteLn('Data saved with chart to ', FILE_NAME, '.ods'); finally - b.Free; + book.Free; end; end. diff --git a/components/fpspreadsheet/examples/other/chart/write_chart_demo.lpr b/components/fpspreadsheet/examples/other/chart/write_chart_demo.lpr index 9cb0cacdc..ab13d2d63 100644 --- a/components/fpspreadsheet/examples/other/chart/write_chart_demo.lpr +++ b/components/fpspreadsheet/examples/other/chart/write_chart_demo.lpr @@ -4,7 +4,9 @@ program write_chart_demo; uses SysUtils, fpspreadsheet, fpstypes, fpsUtils, fpschart, xlsxooxml, fpsopendocument; + const + FILE_NAME = 'test'; // SERIES_CLASS: TsChartSeriesClass = TsAreaSeries; // SERIES_CLASS: TsChartSeriesClass = TsBarSeries; // SERIES_CLASS: TsChartSeriesClass = TsBubbleSeries; @@ -16,18 +18,18 @@ const r2 = 8; FILL_COLORS: array[0..r2-r1] of TsColor = (scRed, scGreen, scBlue, scYellow, scMagenta, scSilver, scBlack, scOlive); var - b: TsWorkbook; + book: TsWorkbook; sheet1, sheet2, sheet3: TsWorksheet; ch: TsChart; ser: TsChartSeries; i: Integer; begin - b := TsWorkbook.Create; + book := TsWorkbook.Create; try // ------------------------------------------------------------------------- // 1st sheet // ------------------------------------------------------------------------- - sheet1 := b.AddWorksheet('test1'); + sheet1 := book.AddWorksheet('test1'); sheet1.WriteText(0, 1, '1+sin(x)'); sheet1.WriteText(0, 2, '1+sin(x/2)'); sheet1.WriteText(0, 3, 'Bubble Radius'); @@ -54,7 +56,7 @@ begin sheet1.WriteNumber(r2, 3, r2*r2); // Create chart - ch := b.AddChart(sheet1, 4, 6, 160, 100); + ch := book.AddChart(sheet1, 4, 6, 160, 100); // Add first series (type depending on SERIES_CLASS) ser := SERIES_CLASS.Create(ch); @@ -113,9 +115,9 @@ begin ch.XAxis.LabelFont.Color := scRed; //ch.XAxis.LabelFont.Style := [fssStrikeout]; ch.XAxis.AxisLine.Color := scRed; - ch.XAxis.Caption := 'This is the x axis'; - ch.XAxis.CaptionFont.Color := scRed; - ch.XAxis.CaptionFont.Size := 12; + ch.XAxis.Title.Caption := 'This is the x axis'; + ch.XAxis.Title.Font.Color := scRed; + ch.XAxis.Title.Font.Size := 12; //ch.XAxis.Inverted := true; ch.XAxis.MajorGridLines.Color := scRed; ch.XAxis.MinorGridLines.Color := scBlue; @@ -127,9 +129,9 @@ begin ch.YAxis.LabelFont.Size := 8; ch.YAxis.LabelFont.Color := scBlue; ch.YAxis.AxisLine.Color := scBlue; - ch.YAxis.Caption := 'This is the y axis'; - ch.YAxis.CaptionFont.Color := scBlue; - ch.YAxis.CaptionFont.Size := 12; + ch.YAxis.Title.Caption := 'This is the y axis'; + ch.YAxis.Title.Font.Color := scBlue; + ch.YAxis.Title.Font.Size := 12; //ch.YAxis.LabelRotation := 90; //ch.YAxis.CaptionRotation := 90; ch.YAxis.Min := -5; @@ -163,13 +165,13 @@ begin // ------------------------------------------------------------------------- // 2nd sheet // ------------------------------------------------------------------------- - sheet2 := b.AddWorksheet('test2'); + sheet2 := book.AddWorksheet('test2'); sheet2.WriteText(0, 0, 'abc'); // ------------------------------------------------------------------------- // 3rd sheet // ------------------------------------------------------------------------- - sheet3 := b.AddWorksheet('test3'); + sheet3 := book.AddWorksheet('test3'); sheet3.WriteText(0, 1, 'cos(x)'); sheet3.WriteText(0, 2, 'sin(x)'); for i := 1 to 7 do @@ -180,7 +182,7 @@ begin end; // Create the chart - ch := b.AddChart(sheet3, 1, 3, 125, 95); + ch := book.AddChart(sheet3, 1, 3, 125, 95); // Add two series ser := TsLineSeries.Create(ch); @@ -210,18 +212,23 @@ begin ch.XAxis.MinorGridLines.Style := clsNoLine; ch.YAxis.MajorGridLines.Style := clsNoLine; ch.YAxis.MinorGridLines.Style := clsNoLine; - ch.YAxis.CaptionRotation := 90; - ch.XAxis.CaptionFont.Size := 14; - ch.YAxis.CaptionFont.Size := 14; + ch.YAxis.Title.RotationAngle := 90; + ch.XAxis.Title.Font.Size := 14; + ch.YAxis.Title.Font.Size := 14; ch.XAxis.LabelFont.Style := [fssItalic]; ch.YAxis.LabelFont.Style := [fssItalic]; ch.YAxis.MajorTicks := [catInside, catOutside]; ch.YAxis.MinorTicks := [catOutside]; - b.WriteToFile('test.xlsx', true); // Excel fails to open the file - b.WriteToFile('test.ods', true); + { + book.WriteToFile(FILE_NAME + '.xlsx', true); // Excel fails to open the file + WriteLn('Data saved with chart in ', FILE_NAME, '.xlsx'); + } + + book.WriteToFile(FILE_NAME + '.ods', true); + WriteLn('Data saved with chart in ', FILE_NAME, '.ods'); finally - b.Free; + book.Free; end; WriteLn; diff --git a/components/fpspreadsheet/source/common/fpschart.pas b/components/fpspreadsheet/source/common/fpschart.pas index a073e8020..5c2d614fe 100644 --- a/components/fpspreadsheet/source/common/fpschart.pas +++ b/components/fpspreadsheet/source/common/fpschart.pas @@ -169,7 +169,6 @@ type private FCaption: String; FRotationAngle: Integer; - FShowCaption: Boolean; FFont: TsFont; FPosX, FPosY: Double; public @@ -177,10 +176,10 @@ type destructor Destroy; override; property Caption: String read FCaption write FCaption; property Font: TsFont read FFont write FFont; - property ShowCaption: Boolean read FShowCaption write FShowCaption; property RotationAngle: Integer read FRotationAngle write FRotationAngle; property PosX: Double read FPosX write FPosX; property PosY: Double read FPosY write FPosY; + property Visible; end; TsChartAxisPosition = (capStart, capEnd, capValue); @@ -196,12 +195,10 @@ type FAutomaticMajorInterval: Boolean; FAutomaticMinorSteps: Boolean; FAxisLine: TsChartLine; + FCategoryRange: TsCellRange; FMajorGridLines: TsChartLine; FMinorGridLines: TsChartline; FInverted: Boolean; - FCaption: String; - FCaptionFont: TsFont; - FCaptionRotation: Integer; FLabelFont: TsFont; FLabelFormat: String; FLabelFormatPercent: String; @@ -211,11 +208,11 @@ type FMajorTicks: TsChartAxisTicks; FMax: Double; FMin: Double; - FMinorSteps: Double; + FMinorCount: Integer; FMinorTicks: TsChartAxisTicks; FPosition: TsChartAxisPosition; + FTitle: TsChartText; FPositionValue: Double; - FShowCaption: Boolean; FShowLabels: Boolean; public constructor Create(AChart: TsChart); @@ -225,9 +222,7 @@ type property AutomaticMajorInterval: Boolean read FAutomaticMajorInterval write FAutomaticMajorInterval; property AutomaticMinorSteps: Boolean read FAutomaticMinorSteps write FAutomaticMinorSteps; property AxisLine: TsChartLine read FAxisLine write FAxisLine; - property Caption: String read FCaption write FCaption; - property CaptionFont: TsFont read FCaptionFont write FCaptionFont; - property CaptionRotation: Integer read FCaptionRotation write FCaptionRotation; + property CategoryRange: TsCellRange read FCategoryRange write FCategoryRange; property Inverted: Boolean read FInverted write FInverted; property LabelFont: TsFont read FLabelFont write FLabelFont; property LabelFormat: String read FLabelFormat write FLabelFormat; @@ -240,12 +235,13 @@ type property Max: Double read FMax write FMax; property Min: Double read FMin write FMin; property MinorGridLines: TsChartLine read FMinorGridLines write FMinorGridLines; - property MinorSteps: Double read FMinorSteps write FMinorSteps; + property MinorCount: Integer read FMinorCount write FMinorCount; property MinorTicks: TsChartAxisTicks read FMinorTicks write FMinorTicks; property Position: TsChartAxisPosition read FPosition write FPosition; property PositionValue: Double read FPositionValue write FPositionValue; - property ShowCaption: Boolean read FShowCaption write FShowCaption; property ShowLabels: Boolean read FShowLabels write FShowLabels; + property Title: TsChartText read FTitle write FTitle; + property Visible; end; TsChartLegendPosition = (lpRight, lpTop, lpBottom, lpLeft); @@ -839,11 +835,11 @@ end; constructor TsChartText.Create(AChart: TsChart); begin inherited Create(AChart); - FShowCaption := true; FFont := TsFont.Create; FFont.Size := 10; FFont.Style := []; FFont.Color := scBlack; + FVisible := true; end; destructor TsChartText.Destroy; @@ -864,10 +860,7 @@ begin FAutomaticMajorInterval := true; FAutomaticMinorSteps := true; - FCaptionFont := TsFont.Create; - FCaptionFont.Size := 10; - FCaptionFont.Style := []; - FCaptionFont.Color := scBlack; + FTitle := TsChartText.Create(AChart); FLabelFont := TsFont.Create; FLabelFont.Size := 9; @@ -875,11 +868,7 @@ begin FLabelFont.Color := scBlack; FLabelFormatPercent := '0%'; - - FCaptionRotation := 0; FLabelRotation := 0; - - FShowCaption := true; FShowLabels := true; FAxisLine := TsChartLine.Create; @@ -907,7 +896,7 @@ begin FMajorGridLines.Free; FAxisLine.Free; FLabelFont.Free; - FCaptionFont.Free; + FTitle.Free; inherited; end; @@ -1318,29 +1307,29 @@ begin FLegend := TsChartLegend.Create(self); FXAxis := TsChartAxis.Create(self); - FXAxis.Caption := 'x axis'; - FXAxis.CaptionFont.Style := [fssBold]; + FXAxis.Title.Caption := 'x axis'; + FXAxis.Title.Font.Style := [fssBold]; FXAxis.LabelFont.Size := 9; FXAxis.Position := capStart; FX2Axis := TsChartAxis.Create(self); - FX2Axis.Caption := 'Secondary x axis'; - FX2Axis.CaptionFont.Style := [fssBold]; + FX2Axis.Title.Caption := 'Secondary x axis'; + FX2Axis.Title.Font.Style := [fssBold]; FX2Axis.LabelFont.Size := 9; FX2Axis.Visible := false; FX2Axis.Position := capEnd; FYAxis := TsChartAxis.Create(self); - FYAxis.Caption := 'y axis'; - FYAxis.CaptionFont.Style := [fssBold]; - FYAxis.CaptionRotation := 90; + FYAxis.Title.Caption := 'y axis'; + FYAxis.Title.Font.Style := [fssBold]; + FYAxis.Title.RotationAngle := 90; FYAxis.LabelFont.Size := 9; FYAxis.Position := capStart; FY2Axis := TsChartAxis.Create(self); - FY2Axis.Caption := 'Secondary y axis'; - FY2Axis.CaptionFont.Style := [fssBold]; - FY2Axis.CaptionRotation := 90; + FY2Axis.Title.Caption := 'Secondary y axis'; + FY2Axis.Title.Font.Style := [fssBold]; + FY2Axis.Title.RotationAngle := 90; FY2Axis.LabelFont.Size := 9; FY2Axis.Visible := false; FY2Axis.Position := capEnd; diff --git a/components/fpspreadsheet/source/common/fpsopendocumentchart.pas b/components/fpspreadsheet/source/common/fpsopendocumentchart.pas index 0fd54bc2a..431a99ee9 100644 --- a/components/fpspreadsheet/source/common/fpsopendocumentchart.pas +++ b/components/fpspreadsheet/source/common/fpsopendocumentchart.pas @@ -23,9 +23,14 @@ type procedure GetChartFillProps(ANode: TDOMNode; AChart: TsChart; AFill: TsChartFill); procedure GetChartLineProps(ANode: TDOMNode; AChart: TsChart; ALine: TsChartLine); + procedure ReadChartAxisGrid(ANode, AStyleNode: TDOMNode; AChart: TsChart; Axis: TsChartAxis); + procedure ReadChartAxisProps(ANode, AStyleNode: TDOMNode; AChart: TsChart); + procedure ReadChartAxisStyle(AStyleNode: TDOMNode; AChart: TsChart; Axis: TsChartAxis); procedure ReadChartBackgroundStyle(AStyleNode: TDOMNode; AChart: TsChart); + procedure ReadChartCellRange(ANode: TDOMNode; AChart: TsChart; var ARange: TsCellRange); procedure ReadChartProps(AChartNode, AStyleNode: TDOMNode; AChart: TsChart); procedure ReadChartPlotAreaProps(ANode, AStyleNode: TDOMNode; AChart: TsChart); + procedure ReadChartPlotAreaStyle(AStyleNode: TDOMNode; AChart: TsChart); procedure ReadChartLegendProps(ANode, AStyleNode: TDOMNode; AChart: TsChart); procedure ReadChartLegendStyle(AStyleNode: TDOMNode; AChart: TsChart); procedure ReadChartTitleProps(ANode, AStyleNode: TDOMNode; AChart: TsChart; ATitle: TsChartText); @@ -451,6 +456,158 @@ begin end; end; +procedure TsSpreadOpenDocChartReader.ReadChartAxisGrid(ANode, AStyleNode: TDOMNode; + AChart: TsChart; Axis: TsChartAxis); +var + s: String; + styleNode: TDOMNode; + grid: TsChartLine; +begin + s := GetAttrValue(ANode, 'chart:class'); + case s of + 'major': grid := Axis.MajorGridLines; + 'minor': grid := Axis.MinorGridLines; + else exit; + end; + + s := GetAttrValue(ANode, 'chart:style-name'); + styleNode := FindStyleNode(AStyleNode, s); + GetChartLineProps(styleNode, AChart, grid); +end; + +procedure TsSpreadOpenDocChartReader.ReadChartAxisProps(ANode, AStyleNode: TDOMNode; + AChart: TsChart); +var + s, styleName, nodeName: String; + styleNode, subNode: TDOMNode; + axis: TsChartAxis; + rng: TsCellRange; +begin + s := GetAttrValue(ANode, 'chart:name'); + case s of + 'primary-x': axis := AChart.XAxis; + 'primary-y': axis := AChart.YAxis; + 'secondary-x': axis := AChart.X2Axis; + 'secondary-y': axis := AChart.Y2Axis; + else raise Exception.Create('Unknown chart axis.'); + end; + + s := GetAttrValue(ANode, 'chart:style-name'); + styleNode := FindStyleNode(AStyleNode, s); + ReadChartAxisStyle(styleNode, AChart, axis); + + subNode := ANode.FirstChild; + while subNode <> nil do + begin + nodeName := subNode.NodeName; + case nodeName of + 'chart:title': + ReadChartTitleProps(subNode, AStyleNode, AChart, axis.Title); + 'chart:categories': + begin + rng := axis.CategoryRange; + ReadChartCellRange(subNode, AChart, rng); + axis.CategoryRange := rng; + end; + 'chart:grid': + ReadChartAxisGrid(subNode, AStyleNode, AChart, axis); + end; + subNode := subNode.NextSibling; + end; +end; + +procedure TsSpreadOpenDocChartReader.ReadChartAxisStyle(AStyleNode: TDOMNode; + AChart: TsChart; Axis: TsChartAxis); +var + nodeName: String; + s: String; + value: Double; + n: Integer; + ticks: TsChartAxisTicks = []; +begin + AStyleNode := AStyleNode.FirstChild; + while AStyleNode <> nil do + begin + nodeName := AStyleNode.NodeName; + case nodeName of + 'style:text-properties': + TsSpreadOpenDocReader(Reader).ReadFont(AStyleNode, Axis.LabelFont); + 'style:graphic-properties': + GetChartLineProps(AStyleNode, AChart, Axis.AxisLine); + 'style:chart-properties': + begin + s := GetAttrValue(AStyleNode, 'chart:display-label'); + if s = 'true' then + Axis.ShowLabels := true; + + s := GetAttrValue(AStyleNode, 'chart:logarithmic'); + if s = 'true' then + Axis.Logarithmic := true; + + s := GetAttrValue(AStyleNode, 'chart:minimum'); + if (s = 'true') and TryStrToFloat(s, value, FPointSeparatorSettings) then + begin + Axis.Min := value; + Axis.AutomaticMin := false; + end else + Axis.AutomaticMin := true; + + s := GetAttrValue(AStyleNode, 'chart:maximum'); + if (s = 'true') and TryStrToFloat(s, value, FPointSeparatorSettings) then + begin + Axis.Max := value; + Axis.AutomaticMax := false; + end else + Axis.AutomaticMax := true; + + s := GetAttrValue(AStyleNode, 'chart:interval-major'); + if (s <> '') and TryStrToFloat(s, value, FPointSeparatorSettings) then + Axis.MajorInterval := value; + + s := GetAttrValue(AStyleNode, 'chart:interval-minor-divisor'); + if (s <> '') and TryStrToInt(s, n) then + Axis.MinorCount := n; + + s := GetAttrValue(AStyleNode, 'chart:axis-position'); + case s of + 'start': + Axis.Position := capStart; + 'end': + Axis.Position := capEnd; + else + if TryStrToFloat(s, value, FPointSeparatorSettings) then + begin + Axis.Position := capValue; + Axis.PositionValue := value; + end; + end; + + ticks := []; // To do: check defaults... + s := GetAttrValue(AStyleNode, 'chart:tick-marks-major-inner'); + if s = 'true' then ticks := ticks + [catInside]; + s := GetAttrValue(AStyleNode, 'chart:tick-marks-major-outer'); + if s = 'true' then ticks := ticks + [catOutside]; + Axis.MajorTicks := ticks; + + ticks := []; // To do: check defaults... + s := GetAttrValue(AStyleNode, 'chart:tick-marks-minor-inner'); + if s = 'true' then ticks := ticks + [catInside]; + s := GetAttrValue(AStyleNode, 'chart:tick-marks-minor-outer'); + if s = 'true' then ticks := ticks + [catOutside]; + Axis.MinorTicks := ticks; + + s := GetAttrValue(AStyleNode, 'chart:reverse-direction'); + if s = 'true' then Axis.Inverted := true; + + s := GetAttrValue(AStyleNode, 'style:rotation-angle'); + if (s <> '') and TryStrToFloat(s, value, FPointSeparatorSettings) then + Axis.LabelRotation := Round(value); + end; + end; + AStyleNode := AStyleNode.NextSibling; + end; +end; + procedure TsSpreadOpenDocChartReader.ReadChartBackgroundStyle(AStyleNode: TDOMNode; AChart: TsChart); var @@ -469,6 +626,20 @@ begin end; end; +procedure TsSpreadOpenDocChartReader.ReadChartCellRange(ANode: TDOMNode; + AChart: TsChart; var ARange: TsCellRange); +var + s: String; + rng: TsCellRange; + sh1, sh2: String; + relFlags: TsRelFlags; +begin + s := GetAttrValue(ANode, 'table:cell-range-address'); + if (s <> '') and TryStrToCellRange_ODS(s, sh1, sh2, rng.Row1, rng.Col1, rng.Row2, rng.Col2, relFlags) then + // TO DO: sheets are ignored here !!! + ARange := rng; +end; + procedure TsSpreadOpenDocChartReader.ReadChartFiles(AStream: TStream; AFileList: String); var @@ -566,7 +737,48 @@ end; procedure TsSpreadOpenDocChartReader.ReadChartPlotAreaProps(ANode, AStyleNode: TDOMNode; AChart: TsChart); +var + nodeName: String; + styleName: String; + styleNode: TDOMNode; begin + styleName := GetAttrValue(ANode, 'chart:style-name'); + styleNode := FindStyleNode(AStyleNode, styleName); + ReadChartPlotAreaStyle(styleNode, AChart); + + ANode := ANode.FirstChild; + while ANode <> nil do + begin + nodeName := ANode.NodeName; + case nodeName of + 'chart:axis': + ReadChartAxisProps(ANode, AStyleNode, AChart); + end; + ANode := ANode.NextSibling; + end; +end; + +procedure TsSpreadOpenDocChartReader.ReadChartPlotAreaStyle(AStyleNode: TDOMNode; AChart: TsChart); +var + nodeName, s: String; +begin + AStyleNode := AStyleNode.FirstChild; + while AStyleNode <> nil do + begin + nodeName := AStyleNode.NodeName; + case nodeName of + 'style:chart-properties': + begin + s := GetAttrValue(AStyleNode, 'chart:stacked'); + if s = 'true' then + AChart.StackMode := csmStacked; + s := GetAttrValue(AStyleNode, 'chart:percentage'); + if s = 'true' then + Achart.StackMode := csmStackedPercentage; + end; + end; + AStyleNode := AStyleNode.NextSibling; + end; end; procedure TsSpreadOpenDocChartReader.ReadChartLegendProps(ANode, AStyleNode: TDOMNode; @@ -1019,7 +1231,7 @@ begin if not Axis.AutomaticMajorInterval then chartProps := chartProps + Format('chart:interval-major="%g" ', [Axis.MajorInterval], FPointSeparatorSettings); if not Axis.AutomaticMinorSteps then - chartProps := chartProps + Format('chart:interval-minor-divisor="%d" ', [Axis.MinorSteps]); + chartProps := chartProps + Format('chart:interval-minor-divisor="%d" ', [Axis.MinorCount]); // Position of the axis case Axis.Position of @@ -1133,8 +1345,8 @@ begin 5: axis := AChart.X2Axis; 6: axis := AChart.Y2Axis; end; - font := axis.CaptionFont; - rotAngle := axis.CaptionRotation; + font := axis.Title.Font; + rotAngle := axis.Title.RotationAngle; if AChart.RotatedAxes then begin if rotAngle = 0 then rotAngle := 90 else if rotAngle = 90 then rotAngle := 0; @@ -1947,13 +2159,13 @@ begin inc(AStyleID); // Axis title - if Axis.ShowCaption and (Axis.Caption <> '') then + if Axis.Title.Visible and (Axis.Title.Caption <> '') then begin AppendToStream(AChartStream, Format( indent + ' ' + LE + indent + ' %s' + LE + indent + ' ' + LE, - [ AStyleID, Axis.Caption ] + [ AStyleID, Axis.Title.Caption ] )); // Axis title style