Axis

Axis class

Encapsulates the object that represents an axis of chart.

class Axis;

Example

const { Workbook, ChartType, CrossType, SaveFormat } = AsposeCells;

//Instantiating a Workbook object
var workbook = new Workbook();
//Adding a new worksheet to the Excel object
var sheetIndex = workbook.worksheets.add();
//Obtaining the reference of the newly added worksheet by passing its sheet index
var worksheet = workbook.worksheets.get(sheetIndex);
//Adding a sample value to "A1" cell
worksheet.cells.get("A1").putValue(50);
//Adding a sample value to "A2" cell
worksheet.cells.get("A2").putValue(100);
//Adding a sample value to "A3" cell
worksheet.cells.get("A3").putValue(150);
//Adding a sample value to "B1" cell
worksheet.cells.get("B1").putValue(4);
//Adding a sample value to "B2" cell
worksheet.cells.get("B2").putValue(20);
//Adding a sample value to "B3" cell
worksheet.cells.get("B3").putValue(50);
//Adding a chart to the worksheet
var chartIndex = worksheet.charts.add(ChartType.Column, 5, 0, 25, 5);
//Accessing the instance of the newly added chart
var chart = worksheet.charts.get(chartIndex);
//Adding NSeries (chart data source) to the chart ranging from "A1" cell to "B3"
chart.nSeries.add("A1:B3", true);
//Set the max value of value axis
chart.valueAxis.maxValue = 200;
//Set the min value of value axis
chart.valueAxis.minValue = 0;
//Set the major unit
chart.valueAxis.majorUnit = 25;
//Category(X) axis crosses at the maxinum value.
chart.valueAxis.crossType = CrossType.Maximum;
//Set he number of categories or series between tick-mark labels. 
chart.categoryAxis.tickLabelSpacing = 2;
//Saving the Excel file
var uint8Array = workbook.save(SaveFormat.Xlsx);

Properties

PropertyTypeDescription
areaAreaReadonly. Gets the Area.
isAutomaticMinValuebooleanIndicates whether the min value is automatically assigned.
minValueVObjectRepresents the minimum value on the value axis.
isAutomaticMaxValuebooleanIndicates whether the max value is automatically assigned.
maxValueVObjectRepresents the maximum value on the value axis.
isAutomaticMajorUnitbooleanIndicates whether the major unit of the axis is automatically assigned.
majorUnitnumberRepresents the major units for the axis.
isAutomaticMinorUnitbooleanIndicates whether the minor unit of the axis is automatically assigned.
minorUnitnumberRepresents the minor units for the axis.
axisLineLineReadonly. Gets the appearance of an Axis.
majorTickMarkTickMarkTypeRepresents the type of major tick mark for the specified axis.
minorTickMarkTickMarkTypeRepresents the type of minor tick mark for the specified axis.
tickLabelPositionTickLabelPositionTypeRepresents the position of tick-mark labels on the specified axis.
crossAtnumberRepresents the point on the value axis where the category axis crosses it.
crossTypeCrossTypeRepresents the CrossType on the specified axis where the other axis crosses.
logBasenumberRepresents the logarithmic base. Default value is 10.Only applies for Excel2007.
isLogarithmicbooleanRepresents if the value axis scale type is logarithmic or not.
isPlotOrderReversedbooleanRepresents if Microsoft Excel plots data points from last to first.
axisBetweenCategoriesbooleanRepresents if the value axis crosses the category axis between categories.
tickLabelsTickLabelsReadonly. Returns a TickLabels object that represents the tick-mark labels for the specified axis.
tickLabelSpacingnumberRepresents the number of categories or series between tick-mark labels. Applies only to category and series axes.
isAutoTickLabelSpacingbooleanIndicates whether the spacing of tick label is automatic
tickMarkSpacingnumberReturns or sets the number of categories or series between tick marks. Applies only to category and series axes.
displayUnitDisplayUnitTypeRepresents the unit label for the specified axis.
customUnitnumberSpecifies a custom value for the display unit.
customDisplayUnitnumberSpecifies a custom value for the display unit.
displayUnitLabelDisplayUnitLabelReadonly. Represents a unit label on an axis in the specified chart. Unit labels are useful for charting large values— for example, in the millions or billions.
isDisplayUnitLabelShownbooleanRepresents if the display unit label is shown on the specified axis.
titleTitleReadonly. Gets the axis’ title.
categoryTypeCategoryTypeRepresents the category axis type.
baseUnitScaleTimeUnitRepresents the base unit scale for the category axis.
majorUnitScaleTimeUnitRepresents the major unit scale for the category axis.
minorUnitScaleTimeUnitRepresents the major unit scale for the category axis.
isVisiblebooleanRepresents if the axis is visible.
majorGridLinesLineReadonly. Represents major gridlines on a chart axis.
minorGridLinesLineReadonly. Represents minor gridlines on a chart axis.
hasMultiLevelLabelsbooleanIndicates whether the labels shall be shown as multi level.
binsAxisBinsReadonly. Represents bins on a chart(Histogram/Pareto) axis

Methods

MethodDescription
getAxisTexts()Gets the labels of the axis after call Chart.Calculate() method.

area

Readonly. Gets the Area.

area : Area;

isAutomaticMinValue

Indicates whether the min value is automatically assigned.

isAutomaticMinValue : boolean;

minValue

Represents the minimum value on the value axis.

minValue : VObject;

Remarks

The minValue type only can be double or DateTime

isAutomaticMaxValue

Indicates whether the max value is automatically assigned.

isAutomaticMaxValue : boolean;

maxValue

Represents the maximum value on the value axis.

maxValue : VObject;

Remarks

The maxValue type only can be double or DateTime

isAutomaticMajorUnit

Indicates whether the major unit of the axis is automatically assigned.

isAutomaticMajorUnit : boolean;

majorUnit

Represents the major units for the axis.

majorUnit : number;

Remarks

The major units must be greater than zero.

isAutomaticMinorUnit

Indicates whether the minor unit of the axis is automatically assigned.

isAutomaticMinorUnit : boolean;

minorUnit

Represents the minor units for the axis.

minorUnit : number;

Remarks

The minor units must be greater than zero.

axisLine

Readonly. Gets the appearance of an Axis.

axisLine : Line;

majorTickMark

Represents the type of major tick mark for the specified axis.

majorTickMark : TickMarkType;

minorTickMark

Represents the type of minor tick mark for the specified axis.

minorTickMark : TickMarkType;

tickLabelPosition

Represents the position of tick-mark labels on the specified axis.

tickLabelPosition : TickLabelPositionType;

crossAt

Represents the point on the value axis where the category axis crosses it.

crossAt : number;

Remarks

The number should be a integer when it applies to category axis. And the value must be between 1 and 31999.

crossType

Represents the CrossType on the specified axis where the other axis crosses.

crossType : CrossType;

logBase

Represents the logarithmic base. Default value is 10.Only applies for Excel2007.

logBase : number;

isLogarithmic

Represents if the value axis scale type is logarithmic or not.

isLogarithmic : boolean;

isPlotOrderReversed

Represents if Microsoft Excel plots data points from last to first.

isPlotOrderReversed : boolean;

axisBetweenCategories

Represents if the value axis crosses the category axis between categories.

axisBetweenCategories : boolean;

Remarks

This property applies only to category axes, and it doesn’t apply to 3-D charts.

tickLabels

Readonly. Returns a TickLabels object that represents the tick-mark labels for the specified axis.

tickLabels : TickLabels;

tickLabelSpacing

Represents the number of categories or series between tick-mark labels. Applies only to category and series axes.

tickLabelSpacing : number;

Remarks

The number must be between 1 and 31999.

isAutoTickLabelSpacing

Indicates whether the spacing of tick label is automatic

isAutoTickLabelSpacing : boolean;

tickMarkSpacing

Returns or sets the number of categories or series between tick marks. Applies only to category and series axes.

tickMarkSpacing : number;

Remarks

The number must be between 1 and 31999.

displayUnit

Represents the unit label for the specified axis.

displayUnit : DisplayUnitType;

customUnit

Specifies a custom value for the display unit.

customUnit : number;

Remarks

NOTE: This property is now obsolete. Instead, please use Axis.CustomDisplayUnit property. This property will be removed 12 months later since February 2025. Aspose apologizes for any inconvenience you may have experienced.

customDisplayUnit

Specifies a custom value for the display unit.

customDisplayUnit : number;

displayUnitLabel

Readonly. Represents a unit label on an axis in the specified chart. Unit labels are useful for charting large values— for example, in the millions or billions.

displayUnitLabel : DisplayUnitLabel;

isDisplayUnitLabelShown

Represents if the display unit label is shown on the specified axis.

isDisplayUnitLabelShown : boolean;

Remarks

The default value is True.

title

Readonly. Gets the axis’ title.

title : Title;

categoryType

Represents the category axis type.

categoryType : CategoryType;

baseUnitScale

Represents the base unit scale for the category axis.

baseUnitScale : TimeUnit;

Remarks

Setting this property only takes effect when the CategoryType property is set to TimeScale.

majorUnitScale

Represents the major unit scale for the category axis.

majorUnitScale : TimeUnit;

Example

const { Workbook, ChartType, CategoryType, TimeUnit } = AsposeCells;

var workbook = new Workbook();
//Adding a new worksheet to the Excel object
var sheetIndex = workbook.worksheets.add();
//Obtaining the reference of the newly added worksheet by passing its sheet index
var worksheet = workbook.worksheets.get(sheetIndex);
//Adding a sample value to "A1" cell
worksheet.cells.get("A1").putValue(50);
//Adding a sample value to "A2" cell
worksheet.cells.get("A2").putValue(100);
//Adding a sample value to "A3" cell
worksheet.cells.get("A3").putValue(150);
//Adding a sample value to "B1" cell
worksheet.cells.get("B1").putValue(4);
//Adding a sample value to "B2" cell
worksheet.cells.get("B2").putValue(20);
//Adding a sample value to "B3" cell
worksheet.cells.get("B3").putValue(50);

//Adding a chart to the worksheet
var chartIndex = worksheet.charts.add(ChartType.Column, 5, 0, 25, 5);
//Accessing the instance of the newly added chart
var chart = worksheet.charts.get(chartIndex);
chart.categoryAxis.categoryType = CategoryType.TimeScale;
chart.categoryAxis.majorUnitScale = TimeUnit.Months;
chart.categoryAxis.majorUnit = 2;

minorUnitScale

Represents the major unit scale for the category axis.

minorUnitScale : TimeUnit;

Example

const { Workbook, ChartType, CategoryType, TimeUnit } = AsposeCells;

var workbook = new Workbook();
//Adding a new worksheet to the Excel object
var sheetIndex = workbook.worksheets.add();
//Obtaining the reference of the newly added worksheet by passing its sheet index
var worksheet = workbook.worksheets.get(sheetIndex);
//Adding a sample value to "A1" cell
worksheet.cells.get("A1").putValue(50);
//Adding a sample value to "A2" cell
worksheet.cells.get("A2").putValue(100);
//Adding a sample value to "A3" cell
worksheet.cells.get("A3").putValue(150);
//Adding a sample value to "B1" cell
worksheet.cells.get("B1").putValue(4);
//Adding a sample value to "B2" cell
worksheet.cells.get("B2").putValue(20);
//Adding a sample value to "B3" cell
worksheet.cells.get("B3").putValue(50);

//Adding a chart to the worksheet
var chartIndex = worksheet.charts.add(ChartType.Column, 5, 0, 25, 5);
//Accessing the instance of the newly added chart
var chart = worksheet.charts.get(chartIndex);
chart.categoryAxis.categoryType = CategoryType.TimeScale;
chart.categoryAxis.minorUnitScale = TimeUnit.Months;
chart.categoryAxis.minorUnit = 2;

isVisible

Represents if the axis is visible.

isVisible : boolean;

majorGridLines

Readonly. Represents major gridlines on a chart axis.

majorGridLines : Line;

Example

const { Workbook, ChartType } = AsposeCells;

var workbook = new Workbook();
//Adding a new worksheet to the Excel object
var sheetIndex = workbook.worksheets.add();
//Obtaining the reference of the newly added worksheet by passing its sheet index
var worksheet = workbook.worksheets.get(sheetIndex);
//Adding a sample value to "A1" cell
worksheet.cells.get("A1").putValue(50);
//Adding a sample value to "A2" cell
worksheet.cells.get("A2").putValue(100);
//Adding a sample value to "A3" cell
worksheet.cells.get("A3").putValue(150);
//Adding a sample value to "B1" cell
worksheet.cells.get("B1").putValue(4);
//Adding a sample value to "B2" cell
worksheet.cells.get("B2").putValue(20);
//Adding a sample value to "B3" cell
worksheet.cells.get("B3").putValue(50);

//Adding a chart to the worksheet
var chartIndex = worksheet.charts.add(ChartType.Column, 5, 0, 25, 5);
//Accessing the instance of the newly added chart
var chart = worksheet.charts.get(chartIndex);
chart.valueAxis.majorGridLines.isVisible = false;
chart.categoryAxis.majorGridLines.isVisible = true;

minorGridLines

Readonly. Represents minor gridlines on a chart axis.

minorGridLines : Line;

hasMultiLevelLabels

Indicates whether the labels shall be shown as multi level.

hasMultiLevelLabels : boolean;

Remarks

Only valid for category axis.

bins

Readonly. Represents bins on a chart(Histogram/Pareto) axis

bins : AxisBins;

getAxisTexts()

Gets the labels of the axis after call Chart.Calculate() method.

getAxisTexts() : string[];

Returns

string[]