HotXLS 文档

TXLSXChart 和 TXLSXCharts 类

TXLSXCharts 是通过 TXLSXWorksheet.Charts 暴露的内嵌图表集合,TXLSXChart 则负责图表的摆放位置、坐标轴和系列

声明

function TXLSXCharts.Add: TXLSXChart; overload;
function TXLSXCharts.Add(AChartType: TXLSXChartType; const ATitle: WideString; AFromRow, AFromCol, AToRow, AToCol: Integer): TXLSXChart; overload;
function TXLSXChart.AddSeries(const AName, ACategories, AValues: WideString): TXLSXChartSeries;
function TXLSXChart.AddPlotGroup(AChartType: TXLSXChartType; AAxisGroup: TXLSXChartAxisGroup = xlsxAxisPrimary): TXLSXChartPlotGroup;
procedure TXLSXChart.ClearSeries;
procedure TXLSXChart.ClearPlotGroups;
procedure TXLSXChart.ClearPreservedXml;
property TXLSXChart.ChartType: TXLSXChartType;
property TXLSXChart.HasPreservedXml: Boolean;
property TXLSXChart.CategoryAxis, ValueAxis: TXLSXChartAxis;
property TXLSXChart.SecondaryCategoryAxis, SecondaryValueAxis: TXLSXChartAxis;
property TXLSXChart.SeriesAxis: TXLSXChartAxis;
property TXLSXChart.TitleTextStyle, LegendTextStyle: TXLSXChartTextStyle;
property TXLSXChart.PlotAreaLayout, TitleLayout, LegendLayout: TXLSXChartLayout;
property TXLSXChart.ShowLegend, TitleOverlay, LegendOverlay: Boolean;
property TXLSXChart.LegendPosition: TXLSXChartLegendPosition;
property TXLSXChart.Series[Index: Integer]: TXLSXChartSeries;
property TXLSXChart.PlotGroups[Index: Integer]: TXLSXChartPlotGroup;
property TXLSXChart.RadarStyle: TXLSXChartRadarStyle;
property TXLSXChart.HoleSize, FirstSliceAng: Integer;
property TXLSXChart.OfPieType: TXLSXChartOfPieType;
property TXLSXChart.OfPieSplitType: TXLSXChartOfPieSplitType;
property TXLSXChart.OfPieSplitPos, OfPieSecondPieSize, OfPieGapWidth: Integer;
property TXLSXChart.RoundedCorners, AutoTitleDeleted: Boolean;
property TXLSXChart.ChartBackgroundColor, ChartBorderColor, PlotAreaBackgroundColor: LongWord;
property TXLSXChart.ProtectionEnabled: Boolean;
property TXLSXChart.ProtectedChartObjects, ProtectedDataEditing, ProtectedFormatting, ProtectedSelection, ProtectedUserInterface: Boolean;
property TXLSXChart.ShowDataTableHorzBorder, ShowDataTableVertBorder, ShowDataTableOutline: Boolean;
property TXLSXChart.HasDropLines, HasSeriesLines: Boolean;
property TXLSXChart.OwnerSheet: TXLSXWorksheet;

图表成员

Title, CategoryAxisTitle and ValueAxisTitle图表和主坐标轴的标题文本
TitleTextStyle and TitleLayout强类型化的图表标题字体、颜色、强调样式、旋转、覆盖与手动位置
ShowLegend, LegendPosition, LegendTextStyle and LegendLayout图例的可见性、方位、覆盖、字体与手动位置
PlotAreaLayout使用归一化 ChartML 坐标手动指定内部或外部绘图区矩形
FromRow, FromCol, ToRow and ToCol从 1 开始的工作表锚定矩形
CategoryAxis and ValueAxis主类别轴(X 轴)和主数值轴(Y 轴)
SecondaryCategoryAxis and SecondaryValueAxis次绘图组使用的顶部和右侧坐标轴
SeriesAxis三维类别图表使用的深度轴
PlotGroups有序的图表族分组,组合图表因此成为可能;Series 仍保留为扁平化的兼容视图
HasPreservedXml报告图表是否保留原始 ChartML,以便扩展安全的 roundtrip
ShowDataTable and ShowDataTableKeys数据表的显示控制开关
ShowDataTableHorzBorder, ShowDataTableVertBorder and ShowDataTableOutline数据表边框的独立开关,分别写出为 c:showHorzBorder、c:showVertBorder 和 c:showOutline;三者默认均为 True
HasDropLines and HasSeriesLines折线图的垂直线把每个数据点连到类别轴;系列线连接堆积条形或折线系列的各段
HasUpDownBars, UpDownGapWidth and HasHiLowLines折线图和股价图的显示控制开关
Rotation3DX, Rotation3DY, Elevation3D, Perspective3D and RightAngleAxes3D三维图表视图控制
HeightPercent3D, DepthPercent3D and GapDepth3D三维绘图的高度、深度和系列间距百分比
RadarStyle当前图表类型对应的雷达图族变体
HoleSize and FirstSliceAng圆环图内径百分比(10..90),以及饼图和圆环图第一扇区的起始角度(度)
OfPieType, OfPieSplitType, OfPieSplitPos, OfPieSecondPieSize and OfPieGapWidth复合饼图和复合条饼图的布局、拆分规则,以及主副绘图区大小
RoundedCorners切换图表空间的圆角
AutoTitleDeleted抑制由单一系列名派生的自动标题,并写出 c:autoTitleDeleted
ChartBackgroundColor, ChartBorderColor and PlotAreaBackgroundColor以 $RRGGBB 值表示的图表和绘图区填充色与边框色;0 表示保留主题默认值
ProtectionEnabled, ProtectedChartObjects, ProtectedDataEditing, ProtectedFormatting, ProtectedSelection and ProtectedUserInterface图表保护总开关,以及以 c:protection 写出的各项编辑限制
OwnerSheet指向拥有该图表的工作表的只读引用

图表类型与组合分组

TXLSXChartType 涵盖柱形图、条形图、折线图、饼图、面积图、圆环图、散点图、气泡图、雷达图、股价图、复合饼图(of-pie)、曲面图、3D 曲面图、3D 柱形图、3D 条形图、3D 折线图、3D 饼图和 3D 面积图等图表族
第一个绘图组是由 ChartType 和 AddSeries 控制的兼容组;其余分组通过 AddPlotGroup 添加,可选用 xlsxAxisPrimary 或 xlsxAxisSecondary

系列、趋势线与误差线

function TXLSXChartSeries.AddTrendline(AType: TXLSXChartTrendlineType): TXLSXChartTrendline;
function TXLSXChartSeries.AddErrorBar(ADir: TXLSXChartErrDir): TXLSXChartErrBar;
property TXLSXChartSeries.Trendlines[Index: Integer]: TXLSXChartTrendline;
property TXLSXChartSeries.ErrBarX, ErrBarY: TXLSXChartErrBar;
property TXLSXChartTrendline.TrendlineType: TXLSXChartTrendlineType;
property TXLSXChartTrendline.DispEq, DispRSqr: Boolean;
property TXLSXChartTrendline.Order, Period: Integer;
property TXLSXChartErrBar.ValueType: TXLSXChartErrValType;
property TXLSXChartErrBar.Value, PlusValue, MinusValue: Double;
TrendlineType线性、指数、对数、多项式、乘幂或移动平均趋势线
DispEq and DispRSqr在图表上显示公式和 R 平方值
Order and Period对应趋势线类型所需的多项式阶数或移动平均周期
ValueType固定值、百分比、标准差、标准误差或自定义误差量
NoEndCap隐藏误差线两端的端帽

坐标轴与数据标签成员

LogBase and Orientation对数刻度底数,以及正向或反向的坐标轴次序
MajorGridlines and MinorGridlines网格线的显示开关
MinValue, MaxValue, MajorUnit and MinorUnit在支持的地方显式指定缩放范围和刻度间距
CrossesAt, TickLblPos and DispUnits坐标轴交叉位置、标签位置和显示单位
ShowValue, ShowCategoryName, ShowSeriesName, ShowLegendKey, ShowPercent and ShowBubbleSize各系列可独立控制的数据标签组成项
Separator多个数据标签组成项同时显示时使用的分隔文本

保留不受支持的 ChartML

启用 TXLSXWorkbook.PreserveUnsupportedParts(默认启用)时,导入的图表会保留其原始 ChartML;未改动的图表会原样重放这份 XML、不做规范化,而对类型化属性的修改则把生成的 HotXLS 模型叠加到原始树上
在编辑已知属性的过程中,未知命名空间、标记兼容性 AlternateContent、扩展列表、自定义样式和未建模的格式会继续附着在各自的图表对象上;调用 ClearPreservedXml 可丢弃单个图表保留的这份 XML,改为仅从类型化属性重新生成

示例

var
  Chart: TXLSXChart;
  Secondary: TXLSXChartPlotGroup;
begin
  Chart := Sheet.Charts.Add(xlsxChartLine, 'Monthly sales', 2, 5, 18, 12);
  Chart.AddSeries('Sales', 'Sheet1!$A$2:$A$13', 'Sheet1!$B$2:$B$13');
  Chart.ValueAxisTitle := 'Amount';
  Chart.TitleTextStyle.Name := 'Aptos Display';
  Chart.TitleTextStyle.Size := 18;
  Chart.TitleTextStyle.Bold := True;
  Chart.PlotAreaLayout.Target := xlsxChartLayoutInner;
  Chart.PlotAreaLayout.SetPositionAndSize(0.12, 0.18, 0.72, 0.64);
  Chart.ShowLegend := True;
  Chart.LegendPosition := xlsxChartLegendBottom;
  Chart.LegendTextStyle.Size := 10;
  Secondary := Chart.AddPlotGroup(xlsxChartColumn, xlsxAxisSecondary);
  Secondary.AddSeries('Margin', 'Sheet1!$A$2:$A$13', 'Sheet1!$C$2:$C$13');
  Chart.SecondaryValueAxis.Title := 'Margin percent';
  Chart.Series[0].AddTrendline(xlsxTrendLinear).DispRSqr := True;
  Chart.Series[0].ShowValue := True;
end;

另请参阅