diff --git a/components/fpspreadsheet/examples/other/chart/write_chart_demo.lpr b/components/fpspreadsheet/examples/other/chart/write_chart_demo.lpr index f84ce90ab..c40c3926f 100644 --- a/components/fpspreadsheet/examples/other/chart/write_chart_demo.lpr +++ b/components/fpspreadsheet/examples/other/chart/write_chart_demo.lpr @@ -61,6 +61,7 @@ begin ser.Line.Color := scBlue; ser.Fill.FgColor := scBlue; ser.SetFillColorRange(r1, 4, r2, 4); + ser.DataLabels := [cdlPercentage, cdlSymbol]; if (ser is TsLineSeries) then begin TsLineSeries(ser).ShowSymbols := true; diff --git a/components/fpspreadsheet/source/common/fpschart.pas b/components/fpspreadsheet/source/common/fpschart.pas index 015c8d31f..ac674d877 100644 --- a/components/fpspreadsheet/source/common/fpschart.pas +++ b/components/fpspreadsheet/source/common/fpschart.pas @@ -185,9 +185,12 @@ type property CanOverlapPlotArea: Boolean read FCanOverlapPlotArea write FCanOverlapPlotArea; property Font: TsFont read FFont write FFont; property Position: TsChartLegendPosition read FPosition write FPosition; + // There is also a "legend-expansion" but this does not seem to have a visual effect in Calc. end; TsChartAxisLink = (alPrimary, alSecondary); + TsChartDataLabel = (cdlValue, cdlPercentage, cdlValueAndPercentage, cdlCategory, cdlSeriesName, cdlSymbol); + TsChartDataLabels = set of TsChartDataLabel; TsChartSeries = class(TsChartElement) private @@ -195,12 +198,14 @@ type FXRange: TsCellRange; // cell range containing the x data FYRange: TsCellRange; FLabelRange: TsCellRange; + FLabelFont: TsFont; FFillColorRange: TsCellRange; FYAxis: TsChartAxisLink; FTitleAddr: TsCellCoord; FLabelFormat: String; FLine: TsChartLine; FFill: TsChartFill; + FDataLabels: TsChartDataLabels; public constructor Create(AChart: TsChart); virtual; destructor Destroy; override; @@ -221,7 +226,9 @@ type property ChartType: TsChartType read FChartType; property Count: Integer read GetCount; + property DataLabels: TsChartDataLabels read FDataLabels write FDataLabels; property FillColorRange: TsCellRange read FFillColorRange; + property LabelFont: TsFont read FLabelFont write FLabelFont; property LabelFormat: String read FLabelFormat write FLabelFormat; // Number format in Excel notation, e.g. '0.00' property LabelRange: TsCellRange read FLabelRange; property TitleAddr: TsCellCoord read FTitleAddr write FTitleAddr; @@ -593,10 +600,15 @@ begin FLine.Style := clsSolid; FLine.Width := PtsToMM(DEFAULT_CHART_LINEWIDTH); FLine.Color := DEFAULT_SERIES_COLORS[idx mod Length(DEFAULT_SERIES_COLORS)]; + + FLabelFont := TsFont.Create; + FLabelFont := TsFont.Create; + FLabelFont.Size := 9; end; destructor TsChartSeries.Destroy; begin + FLabelFont.Free; FLine.Free; FFill.Free; inherited; diff --git a/components/fpspreadsheet/source/common/fpsopendocumentchart.pas b/components/fpspreadsheet/source/common/fpsopendocumentchart.pas index 056473400..95ea85026 100644 --- a/components/fpspreadsheet/source/common/fpsopendocumentchart.pas +++ b/components/fpspreadsheet/source/common/fpsopendocumentchart.pas @@ -527,6 +527,20 @@ begin ); end; chartProps := chartProps + 'chart:link-data-style-to-source="true" '; + if ([cdlValue, cdlPercentage] * series.DataLabels = [cdlValue]) then + chartProps := chartProps + 'chart:data-label-number="value" ' + else + if ([cdlValue, cdlPercentage] * series.DataLabels = [cdlPercentage]) then + chartProps := chartProps + 'chart:data-label-number="percentage" ' + else + if ([cdlValue, cdlPercentage] * series.DataLabels = [cdlValue, cdlPercentage]) then + chartProps := chartProps + 'chart:data-label-number="value-and-percentage" '; + if (cdlCategory in series.DataLabels) then + chartProps := chartProps + 'chart:data-label-text="true" '; + if (cdlSeriesName in series.DataLabels) then + chartProps := chartProps + 'chart:data-label-series="true" '; + if (cdlSymbol in series.DataLabels) then + chartProps := chartProps + 'chart:data-label-symbol="true" '; // Graphic properties lineProps := GetChartLineStyleGraphicPropsAsXML(AChart, series.Line); @@ -541,8 +555,7 @@ begin graphProps := fillProps + lineProps; // Text properties - textProps := 'fo:font-size="10pt" style:font-size-asian="10pt" style:font-size-complex="10pt" '; -// textProps := WriteFontStyleXMLAsString(font); // <--- to be completed. this is for the series labels. + textProps := TsSpreadOpenDocWriter(Writer).WriteFontStyleXMLAsString(series.LabelFont); Result := Format( indent + '' + LE + @@ -1018,7 +1031,7 @@ begin // Write legend properties indent := DupeString(' ', AChartIndent); AppendToStream(AChartStream, Format( - indent + '' + LE, + indent + '' + LE, [ AStyleID, LEGEND_POSITION[AChart.Legend.Position], canOverlap ] )); @@ -1218,12 +1231,10 @@ var indent: String; sheet: TsWorksheet; series: TsChartSeries; - valuesRange: String; + valuesRange: String = ''; domainRangeX: String = ''; domainRangeY: String = ''; fillColorRange: String = ''; - borderColorRange: String = ''; - rangeStr: String = ''; titleAddr: String; count: Integer; begin @@ -1287,6 +1298,8 @@ begin ); count := series.YRange.Row2 - series.YRange.Row1 + 1; + + // Store the series properties AppendToStream(AChartStream, Format( indent + '