Excel.ChartAxis class

代表图表中的单个坐标轴。

扩展

属性

alignment

指定指定轴刻度标签的对齐方式。 请参阅 Excel.ChartTextHorizontalAlignment 了解详细信息。

axisGroup

指定指定轴的组。 有关详细信息,请参阅 Excel.ChartAxisGroup

baseTimeUnit

指定指定类别轴的基本单位。

categoryType

指定类别轴类型。

context

与对象关联的请求上下文。 这将加载项的进程连接到 Office 主机应用程序的进程。

customDisplayUnit

指定自定义轴显示单位值。 要设置此属性,请使用该 SetCustomDisplayUnit(double) 方法。

displayUnit

表示轴显示单位。 有关详细信息,请参阅 Excel.ChartAxisDisplayUnit

format

表示 chart 对象的格式,包括线条和字体格式。

height

指定图表轴的高度(以磅为单位)。 如果轴不可见,则返回 null

isBetweenCategories

指定值轴是否与类别之间的类别轴相交。

left

指定从轴的左边缘到图表区域左侧的距离(以磅为单位)。 如果轴不可见,则返回 null

linkNumberFormat

指定数字格式是否链接到单元格。 如果 ,当 true数字格式在单元格中更改时,标签中的数字格式也会更改。

logBase

指定使用对数刻度时对数的底。

majorGridlines

返回表示指定轴的主要网格线的对象。

majorTickMark

指定指定轴的主刻度线类型。 有关详细信息,请参阅 Excel.ChartAxisTickMark

majorTimeUnitScale

指定属性设置为 dateAxis时类别轴的主要单位比例值。categoryType

majorUnit

表示两个主要刻度标记之间的间隔。 可以设置为数字值或空字符串。 返回的值始终为数字。

maximum

表示数值轴上的最大值。 可以设置为数字值或空字符串(对于自动坐标轴值)。 返回的值始终为数字。

minimum

表示数值轴上的最小值。 可以设置为数字值或空字符串(对于自动坐标轴值)。 返回的值始终为数字。

minorGridlines

返回表示指定轴的次网格线的对象。

minorTickMark

指定指定轴的小刻度线类型。 有关详细信息,请参阅 Excel.ChartAxisTickMark

minorTimeUnitScale

指定属性设置为 dateAxis时类别轴的次单位比例值。categoryType

minorUnit

表示两个次要刻度标记之间的间隔。 可以设置为数字值或空字符串(对于自动坐标轴值)。 返回的值始终为数字。

multiLevel

指定轴是否为多级轴。

numberFormat

指定轴刻度标签的格式代码。

offset

指定标注级别之间的距离以及第一级别与轴线之间的距离。 此值应该是 0 到 1000 之间的整数。

position

指定另一个轴交叉的指定轴位置。 有关详细信息,请参阅 Excel.ChartAxisPosition

positionAt

指定另一个轴相交的轴位置。 应使用该 SetPositionAt(double) 方法设置此属性。

reversePlotOrder

指定 Excel 是否从最后到第一个绘制数据点。

scaleType

指定值轴刻度类型。 有关详细信息,请参阅 Excel.ChartAxisScaleType

showDisplayUnitLabel

指定轴显示单位标签是否可见。

textOrientation

指定图表轴刻度标签的文本定向的角度。 该值应为 -90 到 90 之间的整数,对于垂直方向的文本,应为整数 180。

tickLabelPosition

在指定坐标轴上指定刻度线标签的位置。 有关详细信息,请参阅 Excel.ChartAxisTickLabelPosition

tickLabelSpacing

指定刻度线标签之间的类别数或系列数。 可以是 1 到 31999 的值或空字符串(自动设置)。 返回的值始终为数字。

tickMarkSpacing

指定刻度线之间的类别数或系列数。

title

表示坐标轴标题。

top

指定从轴的顶部边缘到图表区域顶部的距离(以磅为单位)。 如果轴不可见,则返回 null

type

指定坐标轴类型。 有关详细信息,请参阅 Excel.ChartAxisType

visible

指定轴是否可见。

width

指定图表轴的宽度(以磅为单位)。 如果轴不可见,则返回 null

方法

load(options)

将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 context.sync()

load(propertyNames)

将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 context.sync()

load(propertyNamesAndPaths)

将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 context.sync()

set(properties, options)

同时设置对象的多个属性。 可以传递具有相应属性的纯文本对象,也可以传递另一个相同类型的 API 对象。

set(properties)

基于现有加载的对象,同时在对象上设置多个属性。

setCategoryNames(sourceData)

设置指定轴的所有分类名称。

setCustomDisplayUnit(value)

将轴显示单位设为自定义值。

setPositionAt(value)

设置另一个轴交叉处的指定轴位置。

toJSON()

覆盖 JavaScript toJSON() 方法,以便在将 API 对象传递给 JSON.stringify()时提供更有用的输出。 (JSON.stringify反过来调用 toJSON 传递给它的对象的方法。) 虽然原始 Excel.ChartAxis 对象是 API 对象, toJSON 但该方法返回一个纯 JavaScript 对象, (类型化为 Excel.Interfaces.ChartAxisData) ,其中包含从原始对象加载的任何子属性的浅层副本。

属性详细信息

alignment

指定指定轴刻度标签的对齐方式。 请参阅 Excel.ChartTextHorizontalAlignment 了解详细信息。

alignment: Excel.ChartTickLabelAlignment | "Center" | "Left" | "Right";

属性值

Excel.ChartTickLabelAlignment | "Center" | "Left" | "Right"

注解

API 集:ExcelApi 1.8

axisGroup

指定指定轴的组。 有关详细信息,请参阅 Excel.ChartAxisGroup

readonly axisGroup: Excel.ChartAxisGroup | "Primary" | "Secondary";

属性值

Excel.ChartAxisGroup | "Primary" | "Secondary"

注解

API 集:ExcelApi 1.7

baseTimeUnit

指定指定类别轴的基本单位。

baseTimeUnit: Excel.ChartAxisTimeUnit | "Days" | "Months" | "Years";

属性值

Excel.ChartAxisTimeUnit | "Days" | "Months" | "Years"

注解

API 集:ExcelApi 1.7

categoryType

指定类别轴类型。

categoryType: Excel.ChartAxisCategoryType | "Automatic" | "TextAxis" | "DateAxis";

属性值

Excel.ChartAxisCategoryType | "Automatic" | "TextAxis" | "DateAxis"

注解

API 集:ExcelApi 1.7

context

与对象关联的请求上下文。 这将加载项的进程连接到 Office 主机应用程序的进程。

context: RequestContext;

属性值

customDisplayUnit

指定自定义轴显示单位值。 要设置此属性,请使用该 SetCustomDisplayUnit(double) 方法。

readonly customDisplayUnit: number;

属性值

number

注解

API 集:ExcelApi 1.7

displayUnit

表示轴显示单位。 有关详细信息,请参阅 Excel.ChartAxisDisplayUnit

displayUnit: Excel.ChartAxisDisplayUnit | "None" | "Hundreds" | "Thousands" | "TenThousands" | "HundredThousands" | "Millions" | "TenMillions" | "HundredMillions" | "Billions" | "Trillions" | "Custom";

属性值

Excel.ChartAxisDisplayUnit | "None" | "Hundreds" | "Thousands" | "TenThousands" | "HundredThousands" | "Millions" | "TenMillions" | "HundredMillions" | "Billions" | "Trillions" | "Custom"

注解

API 集:ExcelApi 1.7

示例

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/10-chart/chart-axis.yaml

await Excel.run(async (context) => {
    const sheet = context.workbook.worksheets.getItem("Sample");

    let chart = sheet.charts.getItemAt(0);
    let categoryAxis = chart.axes.categoryAxis;
    let valueAxis = chart.axes.valueAxis;

    // Load to get display unit.
    valueAxis.load("displayUnit");

    await context.sync();

    console.log("The vertical axis display unit is: " + valueAxis.displayUnit);
});

format

表示 chart 对象的格式,包括线条和字体格式。

readonly format: Excel.ChartAxisFormat;

属性值

注解

API 集:ExcelApi 1.1

height

指定图表轴的高度(以磅为单位)。 如果轴不可见,则返回 null

readonly height: number;

属性值

number

注解

API 集:ExcelApi 1.7

isBetweenCategories

指定值轴是否与类别之间的类别轴相交。

isBetweenCategories: boolean;

属性值

boolean

注解

API 集:ExcelApi 1.8

left

指定从轴的左边缘到图表区域左侧的距离(以磅为单位)。 如果轴不可见,则返回 null

readonly left: number;

属性值

number

注解

API 集:ExcelApi 1.7

linkNumberFormat

指定数字格式是否链接到单元格。 如果 ,当 true数字格式在单元格中更改时,标签中的数字格式也会更改。

linkNumberFormat: boolean;

属性值

boolean

注解

API 集:ExcelApi 1.9

logBase

指定使用对数刻度时对数的底。

logBase: number;

属性值

number

注解

API 集:ExcelApi 1.7

majorGridlines

返回表示指定轴的主要网格线的对象。

readonly majorGridlines: Excel.ChartGridlines;

属性值

注解

API 集:ExcelApi 1.1

majorTickMark

指定指定轴的主刻度线类型。 有关详细信息,请参阅 Excel.ChartAxisTickMark

majorTickMark: Excel.ChartAxisTickMark | "None" | "Cross" | "Inside" | "Outside";

属性值

Excel.ChartAxisTickMark | "None" | "Cross" | "Inside" | "Outside"

注解

API 集:ExcelApi 1.7

majorTimeUnitScale

指定属性设置为 dateAxis时类别轴的主要单位比例值。categoryType

majorTimeUnitScale: Excel.ChartAxisTimeUnit | "Days" | "Months" | "Years";

属性值

Excel.ChartAxisTimeUnit | "Days" | "Months" | "Years"

注解

API 集:ExcelApi 1.7

majorUnit

表示两个主要刻度标记之间的间隔。 可以设置为数字值或空字符串。 返回的值始终为数字。

majorUnit: any;

属性值

any

注解

API 集:ExcelApi 1.1

maximum

表示数值轴上的最大值。 可以设置为数字值或空字符串(对于自动坐标轴值)。 返回的值始终为数字。

maximum: any;

属性值

any

注解

API 集:ExcelApi 1.1

minimum

表示数值轴上的最小值。 可以设置为数字值或空字符串(对于自动坐标轴值)。 返回的值始终为数字。

minimum: any;

属性值

any

注解

API 集:ExcelApi 1.1

minorGridlines

返回表示指定轴的次网格线的对象。

readonly minorGridlines: Excel.ChartGridlines;

属性值

注解

API 集:ExcelApi 1.1

minorTickMark

指定指定轴的小刻度线类型。 有关详细信息,请参阅 Excel.ChartAxisTickMark

minorTickMark: Excel.ChartAxisTickMark | "None" | "Cross" | "Inside" | "Outside";

属性值

Excel.ChartAxisTickMark | "None" | "Cross" | "Inside" | "Outside"

注解

API 集:ExcelApi 1.7

minorTimeUnitScale

指定属性设置为 dateAxis时类别轴的次单位比例值。categoryType

minorTimeUnitScale: Excel.ChartAxisTimeUnit | "Days" | "Months" | "Years";

属性值

Excel.ChartAxisTimeUnit | "Days" | "Months" | "Years"

注解

API 集:ExcelApi 1.7

minorUnit

表示两个次要刻度标记之间的间隔。 可以设置为数字值或空字符串(对于自动坐标轴值)。 返回的值始终为数字。

minorUnit: any;

属性值

any

注解

API 集:ExcelApi 1.1

multiLevel

指定轴是否为多级轴。

multiLevel: boolean;

属性值

boolean

注解

API 集:ExcelApi 1.8

numberFormat

指定轴刻度标签的格式代码。

numberFormat: string;

属性值

string

注解

API 集:ExcelApi 1.8

offset

指定标注级别之间的距离以及第一级别与轴线之间的距离。 此值应该是 0 到 1000 之间的整数。

offset: number;

属性值

number

注解

API 集:ExcelApi 1.8

position

指定另一个轴交叉的指定轴位置。 有关详细信息,请参阅 Excel.ChartAxisPosition

position: Excel.ChartAxisPosition | "Automatic" | "Maximum" | "Minimum" | "Custom";

属性值

Excel.ChartAxisPosition | "Automatic" | "Maximum" | "Minimum" | "Custom"

注解

API 集:ExcelApi 1.8

positionAt

指定另一个轴相交的轴位置。 应使用该 SetPositionAt(double) 方法设置此属性。

readonly positionAt: number;

属性值

number

注解

API 集:ExcelApi 1.8

reversePlotOrder

指定 Excel 是否从最后到第一个绘制数据点。

reversePlotOrder: boolean;

属性值

boolean

注解

API 集:ExcelApi 1.7

scaleType

指定值轴刻度类型。 有关详细信息,请参阅 Excel.ChartAxisScaleType

scaleType: Excel.ChartAxisScaleType | "Linear" | "Logarithmic";

属性值

Excel.ChartAxisScaleType | "Linear" | "Logarithmic"

注解

API 集:ExcelApi 1.7

showDisplayUnitLabel

指定轴显示单位标签是否可见。

showDisplayUnitLabel: boolean;

属性值

boolean

注解

API 集:ExcelApi 1.7

示例

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/10-chart/chart-axis.yaml

await Excel.run(async (context) => {
    const sheet = context.workbook.worksheets.getItem("Sample");
    let chart = sheet.charts.getItemAt(0);
    let axis = chart.axes.valueAxis;

    // Remove display unit.
    axis.showDisplayUnitLabel = false;

    await context.sync();
});

textOrientation

指定图表轴刻度标签的文本定向的角度。 该值应为 -90 到 90 之间的整数,对于垂直方向的文本,应为整数 180。

textOrientation: any;

属性值

any

注解

API 集:ExcelApi 1.8

tickLabelPosition

在指定坐标轴上指定刻度线标签的位置。 有关详细信息,请参阅 Excel.ChartAxisTickLabelPosition

tickLabelPosition: Excel.ChartAxisTickLabelPosition | "NextToAxis" | "High" | "Low" | "None";

属性值

Excel.ChartAxisTickLabelPosition | "NextToAxis" | "High" | "Low" | "None"

注解

API 集:ExcelApi 1.7

tickLabelSpacing

指定刻度线标签之间的类别数或系列数。 可以是 1 到 31999 的值或空字符串(自动设置)。 返回的值始终为数字。

tickLabelSpacing: any;

属性值

any

注解

API 集:ExcelApi 1.7

tickMarkSpacing

指定刻度线之间的类别数或系列数。

tickMarkSpacing: number;

属性值

number

注解

API 集:ExcelApi 1.7

title

表示坐标轴标题。

readonly title: Excel.ChartAxisTitle;

属性值

注解

API 集:ExcelApi 1.1

top

指定从轴的顶部边缘到图表区域顶部的距离(以磅为单位)。 如果轴不可见,则返回 null

readonly top: number;

属性值

number

注解

API 集:ExcelApi 1.7

type

指定坐标轴类型。 有关详细信息,请参阅 Excel.ChartAxisType

readonly type: Excel.ChartAxisType | "Invalid" | "Category" | "Value" | "Series";

属性值

Excel.ChartAxisType | "Invalid" | "Category" | "Value" | "Series"

注解

API 集:ExcelApi 1.7

visible

指定轴是否可见。

visible: boolean;

属性值

boolean

注解

API 集:ExcelApi 1.7

width

指定图表轴的宽度(以磅为单位)。 如果轴不可见,则返回 null

readonly width: number;

属性值

number

注解

API 集:ExcelApi 1.7

方法详细信息

load(options)

将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 context.sync()

load(options?: Excel.Interfaces.ChartAxisLoadOptions): Excel.ChartAxis;

参数

options
Excel.Interfaces.ChartAxisLoadOptions

为要加载的对象属性提供选项。

返回

load(propertyNames)

将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 context.sync()

load(propertyNames?: string | string[]): Excel.ChartAxis;

参数

propertyNames

string | string[]

指定要加载的属性的逗号分隔的字符串或字符串数组。

返回

示例

// Get the maximum of Chart Axis from Chart1.
await Excel.run(async (context) => { 
    const chart = context.workbook.worksheets.getItem("Sheet1").charts.getItem("Chart1");    
    const axis = chart.axes.valueAxis;
    axis.load('maximum');
    await context.sync();

    console.log(axis.maximum);
});

load(propertyNamesAndPaths)

将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 context.sync()

load(propertyNamesAndPaths?: {
            select?: string;
            expand?: string;
        }): Excel.ChartAxis;

参数

propertyNamesAndPaths

{ select?: string; expand?: string; }

propertyNamesAndPaths.select 是指定要加载的属性的逗号分隔字符串,以及 propertyNamesAndPaths.expand 指定要加载的导航属性的逗号分隔字符串。

返回

set(properties, options)

同时设置对象的多个属性。 可以传递具有相应属性的纯文本对象,也可以传递另一个相同类型的 API 对象。

set(properties: Interfaces.ChartAxisUpdateData, options?: OfficeExtension.UpdateOptions): void;

参数

properties
Excel.Interfaces.ChartAxisUpdateData

一个 JavaScript 对象,其属性与调用该方法的对象的属性同构结构。

options
OfficeExtension.UpdateOptions

提供一个选项,用于在 properties 对象尝试设置任何只读属性时禁止错误。

返回

void

set(properties)

基于现有加载的对象,同时在对象上设置多个属性。

set(properties: Excel.ChartAxis): void;

参数

properties
Excel.ChartAxis

返回

void

setCategoryNames(sourceData)

设置指定轴的所有分类名称。

setCategoryNames(sourceData: Range): void;

参数

sourceData
Excel.Range

Range与源数据对应的对象。

返回

void

注解

API 集:ExcelApi 1.7

setCustomDisplayUnit(value)

将轴显示单位设为自定义值。

setCustomDisplayUnit(value: number): void;

参数

value

number

显示单位的自定义值。

返回

void

注解

API 集:ExcelApi 1.7

setPositionAt(value)

设置另一个轴交叉处的指定轴位置。

setPositionAt(value: number): void;

参数

value

number

交叉点的自定义值。

返回

void

注解

API 集:ExcelApi 1.8

toJSON()

覆盖 JavaScript toJSON() 方法,以便在将 API 对象传递给 JSON.stringify()时提供更有用的输出。 (JSON.stringify反过来调用 toJSON 传递给它的对象的方法。) 虽然原始 Excel.ChartAxis 对象是 API 对象, toJSON 但该方法返回一个纯 JavaScript 对象, (类型化为 Excel.Interfaces.ChartAxisData) ,其中包含从原始对象加载的任何子属性的浅层副本。

toJSON(): Excel.Interfaces.ChartAxisData;

返回