diff --git a/components/fpspreadsheet/examples/visual/fpschart/fpschartlink/main.pas b/components/fpspreadsheet/examples/visual/fpschart/fpschartlink/main.pas index c6c8f3ca6..2ec734caf 100644 --- a/components/fpspreadsheet/examples/visual/fpschart/fpschartlink/main.pas +++ b/components/fpspreadsheet/examples/visual/fpschart/fpschartlink/main.pas @@ -64,8 +64,11 @@ end; procedure TForm1.ComboBox1CloseUp(Sender: TObject); begin - Combobox1.Text := Combobox1.Items[Combobox1.ItemIndex]; - LoadFile(Combobox1.Text); + if ComboBox1.ItemIndex > -1 then + begin + Combobox1.Text := Combobox1.Items[Combobox1.ItemIndex]; + LoadFile(Combobox1.Text); + end; end; procedure TForm1.FormCreate(Sender: TObject); diff --git a/components/fpspreadsheet/source/common/fpschart.pas b/components/fpspreadsheet/source/common/fpschart.pas index a87ff87b9..1b5dd4050 100644 --- a/components/fpspreadsheet/source/common/fpschart.pas +++ b/components/fpspreadsheet/source/common/fpschart.pas @@ -247,6 +247,8 @@ type FInverted: Boolean; FLabelFont: TsFont; FLabelFormat: String; + FLabelFormatFromSource: Boolean; + FLabelFormatDateTime: String; FLabelFormatPercent: String; FLabelRotation: Integer; FLogarithmic: Boolean; @@ -274,6 +276,8 @@ type property Inverted: Boolean read FInverted write FInverted; property LabelFont: TsFont read FLabelFont write FLabelFont; property LabelFormat: String read FLabelFormat write FLabelFormat; + property LabelFormatDateTime: String read FLabelFormatDateTime write FLabelFormatDateTime; + property LabelFormatFromSource: Boolean read FLabelFormatFromSource write FLabelFormatFromSource; property LabelFormatPercent: String read FLabelFormatPercent write FLabelFormatPercent; property LabelRotation: Integer read FLabelRotation write FLabelRotation; property Logarithmic: Boolean read FLogarithmic write FLogarithmic; @@ -1190,6 +1194,8 @@ begin FLabelFont.Style := []; FLabelFont.Color := scBlack; + FLabelFormatFromSource := true; + FLabelFormatDateTime := ''; FLabelFormatPercent := '0%'; FLabelRotation := 0; FShowLabels := true; diff --git a/components/fpspreadsheet/source/common/fpsopendocumentchart.pas b/components/fpspreadsheet/source/common/fpsopendocumentchart.pas index 95a5f4fa0..ca80abd51 100644 --- a/components/fpspreadsheet/source/common/fpsopendocumentchart.pas +++ b/components/fpspreadsheet/source/common/fpsopendocumentchart.pas @@ -12,7 +12,8 @@ uses fpszipper, {$ENDIF} laz2_xmlread, laz2_DOM, - fpsTypes, fpSpreadsheet, fpsChart, fpsUtils, fpsReaderWriter, fpsXMLCommon; + fpsTypes, fpSpreadsheet, fpsChart, fpsUtils, fpsNumFormat, + fpsReaderWriter, fpsXMLCommon; type @@ -693,9 +694,15 @@ var ticks: TsChartAxisTicks = []; begin nodeName := AStyleNode.NodeName; + s := GetAttrValue(AStyleNode, 'style:data-style-name'); if s <> '' then s := TsChartNumberFormatList(FNumberFormatList).FindFormatByName(s); + if IsDateTimeFormat(s) then + begin + Axis.DateTime := true; + Axis.LabelFormatDateTime := s; + end else if (AChart.StackMode = csmStackedPercentage) and ((Axis = AChart.YAxis) or (Axis = AChart.Y2Axis)) then Axis.LabelFormatPercent := s else diff --git a/components/fpspreadsheet/source/visual/fpspreadsheetchart.pas b/components/fpspreadsheet/source/visual/fpspreadsheetchart.pas index 2c55b6a52..70310a6a5 100644 --- a/components/fpspreadsheet/source/visual/fpspreadsheetchart.pas +++ b/components/fpspreadsheet/source/visual/fpspreadsheetchart.pas @@ -27,7 +27,7 @@ uses TASeries, TARadialSeries, TAFitUtils, TAFuncSeries, TAMultiSeries, TATransformations, TAChartAxisUtils, TAChartAxis, TAStyles, TATools, TAGraph, // FPSpreadsheet - fpsTypes, fpSpreadsheet, fpsUtils, fpsChart, + fpsTypes, fpSpreadsheet, fpsUtils, fpsNumFormat, fpsChart, // FPSpreadsheet Visual fpSpreadsheetCtrls, fpSpreadsheetGrid, fpsVisualUtils; @@ -1141,7 +1141,7 @@ begin Result.Title := src.Title; end; - // Assign series to axis for primary and secondary axes support + // Assign series index to axis for primary and secondary axes support case ASeries.XAxis of alPrimary: Result.AxisIndexX := FChart.AxisList.GetAxisByAlign(calBottom).Index; @@ -1785,6 +1785,9 @@ begin // Labels Convert_sFont_to_Font(AWorkbookAxis.LabelFont, axis.Marks.LabelFont); axis.Marks.LabelFont.Orientation := round(AWorkbookAxis.LabelRotation * 10); + if (AWorkbookAxis.LabelFormat <> '') and not IsDateTimeFormat(AWorkbookAxis.LabelFormat) then + axis.Marks.Format := Convert_NumFormatStr_to_FormatStr(AWorkbookAxis.LabelFormat); + // Axis line UpdateChartPen(AWorkbookAxis.Chart, AWorkbookAxis.AxisLine, axis.AxisPen); @@ -1839,9 +1842,34 @@ begin axis.Intervals.MinLength := 20; axis.Intervals.Tolerance := 0; end; +end; + +procedure TsWorkbookChartLink.UpdateChartAxisLabels(AWorkbookChart: TsChart); +var + axis: TChartAxis; +begin + if FChart.SeriesCount = 0 then + exit; + + axis := FChart.BottomAxis; + case AWorkbookChart.GetChartType of + ctScatter, ctBubble: + begin + axis.Marks.Source := nil; + axis.Marks.Style := smsValue; + end; + ctBar, ctLine, ctArea: + begin + axis.Marks.Source := TChartSeries(FChart.Series[0]).Source; + if not AWorkbookChart.Series[0].LabelRange.IsEmpty then + axis.Marks.Style := smsLabel + else + axis.Marks.Style := smsXValue; + end; + end; // Date/time? - if AWorkbookAxis.DateTime then + if AWorkbookChart.XAxis.DateTime then begin axis.Marks.Source := TDateTimeIntervalChartsource.Create(FChart); axis.Marks.Style := smsLabel; @@ -1853,28 +1881,6 @@ begin end; end; -procedure TsWorkbookChartLink.UpdateChartAxisLabels(AWorkbookChart: TsChart); -begin - if FChart.SeriesCount = 0 then - exit; - - case AWorkbookChart.GetChartType of - ctScatter, ctBubble: - begin - FChart.BottomAxis.Marks.Source := nil; - FChart.BottomAxis.Marks.Style := smsValue; - end; - ctBar, ctLine, ctArea: - begin - FChart.BottomAxis.Marks.Source := TChartSeries(FChart.Series[0]).Source; - if not AWorkbookChart.Series[0].LabelRange.IsEmpty then - FChart.BottomAxis.Marks.Style := smsLabel - else - FChart.BottomAxis.Marks.Style := smsXValue; - end; - end; -end; - procedure TsWorkbookChartLink.UpdateChartBackground(AWorkbookChart: TsChart); begin FChart.Color := Convert_sColor_to_Color(AWorkbookChart.Background.Color);