You've already forked lazarus-ccr
fpspreadsheet: Add TsAreaSeries. Add stack and 100%-stack modes (not working)
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@8988 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@ -5,7 +5,7 @@ program write_chart_demo;
|
|||||||
uses
|
uses
|
||||||
SysUtils, fpspreadsheet, fpstypes, fpschart, xlsxooxml, fpsopendocument;
|
SysUtils, fpspreadsheet, fpstypes, fpschart, xlsxooxml, fpsopendocument;
|
||||||
const
|
const
|
||||||
SERIES_CLASS: TsChartSeriesClass = TsBarSeries;
|
SERIES_CLASS: TsChartSeriesClass = TsAreaSeries;
|
||||||
var
|
var
|
||||||
b: TsWorkbook;
|
b: TsWorkbook;
|
||||||
sh1, sh2, sh3: TsWorksheet;
|
sh1, sh2, sh3: TsWorksheet;
|
||||||
@ -63,20 +63,21 @@ begin
|
|||||||
ch.Background.Style := fsSolidFill;
|
ch.Background.Style := fsSolidFill;
|
||||||
ch.Border.Style := clsSolid;
|
ch.Border.Style := clsSolid;
|
||||||
ch.PlotArea.Background.Style := fsSolidFill;
|
ch.PlotArea.Background.Style := fsSolidFill;
|
||||||
ch.RotatedAxes := true;
|
//ch.RotatedAxes := true;
|
||||||
|
ch.StackMode := csmStackedPercentage;
|
||||||
|
|
||||||
ch.XAxis.ShowLabels := true;
|
ch.XAxis.ShowLabels := true;
|
||||||
ch.XAxis.LabelFont.Size := 8;
|
ch.XAxis.LabelFont.Size := 9;
|
||||||
ch.XAxis.LabelFont.Color := scRed;
|
ch.XAxis.LabelFont.Color := scRed;
|
||||||
ch.XAxis.LabelFont.Style := [fssStrikeout];
|
//ch.XAxis.LabelFont.Style := [fssStrikeout];
|
||||||
ch.XAxis.AxisLine.Color := scRed;
|
ch.XAxis.AxisLine.Color := scRed;
|
||||||
ch.XAxis.Caption := 'This is the x axis';
|
ch.XAxis.Caption := 'This is the x axis';
|
||||||
ch.XAxis.CaptionFont.Color := scRed;
|
ch.XAxis.CaptionFont.Color := scRed;
|
||||||
ch.XAxis.CaptionFont.Size := 12;
|
ch.XAxis.CaptionFont.Size := 12;
|
||||||
ch.XAxis.Inverted := true;
|
//ch.XAxis.Inverted := true;
|
||||||
ch.XAxis.MajorGridLines.Color := scRed;
|
ch.XAxis.MajorGridLines.Color := scRed;
|
||||||
ch.XAxis.MinorGridLines.Color := scBlue;
|
ch.XAxis.MinorGridLines.Color := scBlue;
|
||||||
ch.XAxis.MajorGridLines.Style := clsNoLine;//Solid;
|
ch.XAxis.MajorGridLines.Style := clsNoLine; //Solid;
|
||||||
ch.XAxis.MinorGridLines.Style := clsNoLine; //Solid;
|
ch.XAxis.MinorGridLines.Style := clsNoLine; //Solid;
|
||||||
|
|
||||||
ch.YAxis.ShowLabels := true;
|
ch.YAxis.ShowLabels := true;
|
||||||
@ -86,8 +87,8 @@ begin
|
|||||||
ch.YAxis.Caption := 'This is the y axis';
|
ch.YAxis.Caption := 'This is the y axis';
|
||||||
ch.YAxis.CaptionFont.Color := scBlue;
|
ch.YAxis.CaptionFont.Color := scBlue;
|
||||||
ch.YAxis.CaptionFont.Size := 12;
|
ch.YAxis.CaptionFont.Size := 12;
|
||||||
ch.YAxis.LabelRotation := 90;
|
//ch.YAxis.LabelRotation := 90;
|
||||||
ch.YAxis.CaptionRotation := 90;
|
//ch.YAxis.CaptionRotation := 90;
|
||||||
ch.YAxis.MajorGridLines.Color := scBlue;
|
ch.YAxis.MajorGridLines.Color := scBlue;
|
||||||
ch.YAxis.MajorGridLines.Style := clsLongDash; //clsSolid;
|
ch.YAxis.MajorGridLines.Style := clsLongDash; //clsSolid;
|
||||||
ch.YAxis.MajorGridLines.Width := 0.5; // mm
|
ch.YAxis.MajorGridLines.Width := 0.5; // mm
|
||||||
|
@ -230,6 +230,11 @@ type
|
|||||||
end;
|
end;
|
||||||
TsChartSeriesClass = class of TsChartSeries;
|
TsChartSeriesClass = class of TsChartSeries;
|
||||||
|
|
||||||
|
TsAreaSeries = class(TsChartSeries)
|
||||||
|
public
|
||||||
|
constructor Create(AChart: TsChart); override;
|
||||||
|
end;
|
||||||
|
|
||||||
TsBarSeries = class(TsChartSeries)
|
TsBarSeries = class(TsChartSeries)
|
||||||
public
|
public
|
||||||
constructor Create(AChart: TsChart); override;
|
constructor Create(AChart: TsChart); override;
|
||||||
@ -268,6 +273,8 @@ type
|
|||||||
property Items[AIndex: Integer]: TsChartSeries read GetItem write SetItem; default;
|
property Items[AIndex: Integer]: TsChartSeries read GetItem write SetItem; default;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
TsChartStackMode =(csmSideBySide, csmStacked, csmStackedPercentage);
|
||||||
|
|
||||||
TsChart = class(TsChartFillElement)
|
TsChart = class(TsChartFillElement)
|
||||||
private
|
private
|
||||||
FIndex: Integer; // Index in workbook's chart list
|
FIndex: Integer; // Index in workbook's chart list
|
||||||
@ -284,6 +291,7 @@ type
|
|||||||
FY2Axis: TsChartAxis;
|
FY2Axis: TsChartAxis;
|
||||||
|
|
||||||
FRotatedAxes: Boolean; // For bar series: vertical columns <--> horizontal bars
|
FRotatedAxes: Boolean; // For bar series: vertical columns <--> horizontal bars
|
||||||
|
FStackMode: TsChartStackMode;
|
||||||
|
|
||||||
FTitle: TsChartText;
|
FTitle: TsChartText;
|
||||||
FSubTitle: TsChartText;
|
FSubTitle: TsChartText;
|
||||||
@ -350,8 +358,11 @@ type
|
|||||||
property YAxis: TsChartAxis read FYAxis write FYAxis;
|
property YAxis: TsChartAxis read FYAxis write FYAxis;
|
||||||
{ Attributes of the plot's secondary y axis (right) }
|
{ Attributes of the plot's secondary y axis (right) }
|
||||||
property Y2Axis: TsChartAxis read FY2Axis write FY2Axis;
|
property Y2Axis: TsChartAxis read FY2Axis write FY2Axis;
|
||||||
|
|
||||||
{ x and y axes exchanged (for bar series) }
|
{ x and y axes exchanged (for bar series) }
|
||||||
property RotatedAxes: Boolean read FRotatedAxes write FRotatedAxes;
|
property RotatedAxes: Boolean read FRotatedAxes write FRotatedAxes;
|
||||||
|
{ stacked series }
|
||||||
|
property StackMode: TsChartStackMode read FStackMode write FStackMode;
|
||||||
|
|
||||||
property CategoryLabelRange: TsCellRange read GetCategoryLabelRange;
|
property CategoryLabelRange: TsCellRange read GetCategoryLabelRange;
|
||||||
|
|
||||||
@ -685,6 +696,15 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
{ TsAreaSeries }
|
||||||
|
|
||||||
|
constructor TsAreaSeries.Create(AChart: TsChart);
|
||||||
|
begin
|
||||||
|
inherited Create(AChart);
|
||||||
|
FChartType := ctArea;
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
{ TsBarSeries }
|
{ TsBarSeries }
|
||||||
|
|
||||||
constructor TsBarSeries.Create(AChart: TsChart);
|
constructor TsBarSeries.Create(AChart: TsChart);
|
||||||
|
@ -311,7 +311,7 @@ type
|
|||||||
AChartIndent, AStyleIndent: Integer; AChart: TsChart; var AStyleID: Integer);
|
AChartIndent, AStyleIndent: Integer; AChart: TsChart; var AStyleID: Integer);
|
||||||
procedure WriteChartLegend(AChartStream, AStyleStream: TStream;
|
procedure WriteChartLegend(AChartStream, AStyleStream: TStream;
|
||||||
AChartIndent, AStyleIndent: Integer; AChart: TsChart; var AStyleID: Integer);
|
AChartIndent, AStyleIndent: Integer; AChart: TsChart; var AStyleID: Integer);
|
||||||
procedure WriteChartNumberStyles(AStream: TStream; AIndent: Integer);
|
procedure WriteChartNumberStyles(AStream: TStream; AIndent: Integer; AChart: TsChart);
|
||||||
procedure WriteChartPlotArea(AChartStream, AStyleStream: TStream;
|
procedure WriteChartPlotArea(AChartStream, AStyleStream: TStream;
|
||||||
AChartIndent, AStyleIndent: Integer; AChart: TsChart; var AStyleID: Integer);
|
AChartIndent, AStyleIndent: Integer; AChart: TsChart; var AStyleID: Integer);
|
||||||
procedure WriteChartSeries(AChartStream, AStyleStream: TStream;
|
procedure WriteChartSeries(AChartStream, AStyleStream: TStream;
|
||||||
@ -6771,7 +6771,7 @@ begin
|
|||||||
chartStream := TMemoryStream.Create;
|
chartStream := TMemoryStream.Create;
|
||||||
styleStream := TMemoryStream.Create;
|
styleStream := TMemoryStream.Create;
|
||||||
try
|
try
|
||||||
WriteChartNumberStyles(styleStream, 4);
|
WriteChartNumberStyles(styleStream, 4, AChart);
|
||||||
|
|
||||||
styleID := 1;
|
styleID := 1;
|
||||||
WriteChartBackground(chartStream, styleStream, 6, 4, AChart, styleID);
|
WriteChartBackground(chartStream, styleStream, 6, 4, AChart, styleID);
|
||||||
@ -7043,7 +7043,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TsSpreadOpenDocWriter.WriteChartNumberStyles(AStream: TStream;
|
procedure TsSpreadOpenDocWriter.WriteChartNumberStyles(AStream: TStream;
|
||||||
AIndent: Integer);
|
AIndent: Integer; AChart: TsChart);
|
||||||
var
|
var
|
||||||
indent: String;
|
indent: String;
|
||||||
begin
|
begin
|
||||||
@ -7055,7 +7055,13 @@ begin
|
|||||||
indent + '</number:number-style>' + LE
|
indent + '</number:number-style>' + LE
|
||||||
);
|
);
|
||||||
|
|
||||||
// Other styles follow here, for example for "percentage" stacked bars.
|
if AChart.StackMode = csmStackedPercentage then
|
||||||
|
AppendToStream(AStream,
|
||||||
|
indent + '<number:percentage-style style:name="N10010">' + LE +
|
||||||
|
indent + ' <number:number number:decimal-places="0" number:min-decimal-places="0" number:min-integer-digits="1"/>' + LE +
|
||||||
|
indent + ' <number:text>%</number:text>' + LE +
|
||||||
|
indent + '</number:percentage-style>' + LE
|
||||||
|
);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TsSpreadOpenDocWriter.WriteChartPlotArea(AChartStream, AStyleStream: TStream;
|
procedure TsSpreadOpenDocWriter.WriteChartPlotArea(AChartStream, AStyleStream: TStream;
|
||||||
@ -7191,6 +7197,7 @@ var
|
|||||||
textProps: String = '';
|
textProps: String = '';
|
||||||
graphProps: String = '';
|
graphProps: String = '';
|
||||||
chartProps: String = '';
|
chartProps: String = '';
|
||||||
|
numStyle: String = 'N0';
|
||||||
begin
|
begin
|
||||||
Result := '';
|
Result := '';
|
||||||
if not Axis.Visible then
|
if not Axis.Visible then
|
||||||
@ -7198,6 +7205,9 @@ begin
|
|||||||
|
|
||||||
chart := Axis.Chart;
|
chart := Axis.Chart;
|
||||||
|
|
||||||
|
if (Axis = chart.YAxis) and (chart.StackMode = csmStackedPercentage) then
|
||||||
|
numStyle := 'N10010';
|
||||||
|
|
||||||
if Axis.ShowLabels then
|
if Axis.ShowLabels then
|
||||||
chartProps := chartProps + 'chart:display-label="true" ';
|
chartProps := chartProps + 'chart:display-label="true" ';
|
||||||
|
|
||||||
@ -7208,12 +7218,6 @@ begin
|
|||||||
chartProps := chartProps + 'chart:reverse-direction="true" ';
|
chartProps := chartProps + 'chart:reverse-direction="true" ';
|
||||||
|
|
||||||
angle := Axis.LabelRotation;
|
angle := Axis.LabelRotation;
|
||||||
{
|
|
||||||
if chart.RotatedAxes then
|
|
||||||
begin
|
|
||||||
if angle = 0 then angle := 90 else if angle = 90 then angle := 0;
|
|
||||||
end;
|
|
||||||
}
|
|
||||||
chartProps := chartProps + Format('style:rotation-angle="%d" ', [angle]);
|
chartProps := chartProps + Format('style:rotation-angle="%d" ', [angle]);
|
||||||
|
|
||||||
graphProps := 'svg:stroke-color="' + ColorToHTMLColorStr(Axis.AxisLine.Color) + '" ';
|
graphProps := 'svg:stroke-color="' + ColorToHTMLColorStr(Axis.AxisLine.Color) + '" ';
|
||||||
@ -7222,12 +7226,12 @@ begin
|
|||||||
|
|
||||||
indent := DupeString(' ', AIndent);
|
indent := DupeString(' ', AIndent);
|
||||||
Result := Format(
|
Result := Format(
|
||||||
indent + '<style:style style:name="ch%d" style:family="chart" style:data-style-name="N0">' + LE +
|
indent + '<style:style style:name="ch%d" style:family="chart" style:data-style-name="%s">' + LE +
|
||||||
indent + ' <style:chart-properties %s/>' + LE +
|
indent + ' <style:chart-properties %s/>' + LE +
|
||||||
indent + ' <style:graphic-properties %s/>' + LE +
|
indent + ' <style:graphic-properties %s/>' + LE +
|
||||||
indent + ' <style:text-properties %s/>' + LE +
|
indent + ' <style:text-properties %s/>' + LE +
|
||||||
indent + '</style:style>' + LE,
|
indent + '</style:style>' + LE,
|
||||||
[ AStyleID, chartProps, graphProps, textProps ]
|
[ AStyleID, numStyle, chartProps, graphProps, textProps ]
|
||||||
);
|
);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -7429,16 +7433,23 @@ function TsSpreadOpenDocWriter.GetChartPlotAreaStyleAsXML(AChart: TsChart;
|
|||||||
var
|
var
|
||||||
indent: String;
|
indent: String;
|
||||||
verticalStr: String = '';
|
verticalStr: String = '';
|
||||||
|
stackModeStr: String = '';
|
||||||
begin
|
begin
|
||||||
indent := DupeString(' ', AIndent);
|
indent := DupeString(' ', AIndent);
|
||||||
|
|
||||||
if (AChart.Series.Count > 0) and (AChart.Series[0] is TsBarSeries) and AChart.RotatedAxes then
|
if AChart.RotatedAxes then
|
||||||
verticalStr := 'chart:vertical="true" ';
|
verticalStr := 'chart:vertical="true" ';
|
||||||
|
case AChart.StackMode of
|
||||||
|
csmSideBySide: ;
|
||||||
|
csmStacked: stackModeStr := 'chart:stacked="true" ';
|
||||||
|
csmStackedPercentage: stackModeStr := 'chart:percentage="true" ';
|
||||||
|
end;
|
||||||
|
|
||||||
Result := Format(
|
Result := Format(
|
||||||
indent + ' <style:style style:name="ch%d" style:family="chart">' + LE +
|
indent + ' <style:style style:name="ch%d" style:family="chart">' + LE +
|
||||||
indent + ' <style:chart-properties ' +
|
indent + ' <style:chart-properties ' +
|
||||||
verticalStr +
|
verticalStr +
|
||||||
|
stackModeStr +
|
||||||
'chart:symbol-type="automatic" ' +
|
'chart:symbol-type="automatic" ' +
|
||||||
'chart:include-hidden-cells="false" ' +
|
'chart:include-hidden-cells="false" ' +
|
||||||
'chart:auto-position="true" ' +
|
'chart:auto-position="true" ' +
|
||||||
|
Reference in New Issue
Block a user