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