DataLabel 对象 (Excel)DataLabel object (Excel)

代表图表数据点或趋势线上的数据标签。Represents the data label on a chart point or trendline.


在系列中, DataLabel对象是**DataLabels** 集合的一个成员。In a series, the DataLabel object is a member of the DataLabels collection. 数据标签 集合中包含的每个点的 数据标签 对象。The DataLabels collection contains a DataLabel object for each point. 对于未定义点的序列(例如区域序列),DataLabels 集合包含单个 DataLabel 对象。For a series without definable points (such as an area series), the DataLabels collection contains a single DataLabel object.


使用**DataLabels** (索引), 其中_索引_是数据标签索引号, 返回单个DataLabel对象。Use DataLabels (index), where index is the data-label index number, to return a single DataLabel object. 下例设置第一个工作表第一个内嵌图表的第一个序列中第五个数据标签的数字格式。The following example sets the number format for the fifth data label in series one in embedded chart one on worksheet one.

Worksheets(1).ChartObjects(1).Chart _ 
 .SeriesCollection(1).DataLabels(5).NumberFormat = "0.000"

使用Point对象的**DataLabel** 属性可返回单个点的DataLabel对象。Use the DataLabel property of the Point object to return the DataLabel object for a single point. 以下示例打开名为 " Chart1" 的图表工作表上第一个数据系列中第二个数据点的数据标签, 并将数据标签文本设置为星期六The following example turns on the data label for the second point in series one on the chart sheet named Chart1, and sets the data label text to Saturday.

With Charts("chart1") 
 With .SeriesCollection(1).Points(2) 
 .HasDataLabel = True 
 .DataLabel.Text = "Saturday" 
 End With 
End With

在趋势线上, DataLabel 属性返回与趋势线一起显示的文本。On a trendline, the DataLabel property returns the text shown with the trendline. 这些文本可能是公式和/或 R 平方值(如果两者都出现)。This can be the equation, the R-squared value, or both (if both are showing). 以下示例将趋势线文本设置为仅显示公式, 然后将数据标签文本放在名为Sheet1的工作表上的单元格 A1 中。The following example sets the trendline text to show only the equation, and then places the data label text in cell A1 on the worksheet named Sheet1.

With Charts("chart1").SeriesCollection(1).Trendlines(1) 
 .DisplayRSquared = False 
 .DisplayEquation = True 
 Worksheets("sheet1").Range("a1").Value = .DataLabel.Text 
End With



另请参阅See also

支持和反馈Support and feedback

有关于 Office VBA 或本文档的疑问或反馈?Have questions or feedback about Office VBA or this documentation? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.