Class Axis

Axis class

Encapsulates the object that represents an axis of chart.

public class Axis

Properties

NameDescription
Area { get; }Gets the Area.
AxisBetweenCategories { get; set; }Represents if the value axis crosses the category axis between categories.
AxisLabels { get; }(Obsolete.) Gets the labels of the axis after call Chart.Calculate() method.
AxisLine { get; }Gets the appearance of an Axis.
BaseUnitScale { get; set; }Represents the base unit scale for the category axis.
Bins { get; }Represents bins on a chart(Histogram/Pareto) axis
CategoryType { get; set; }Represents the category axis type.
CrossAt { get; set; }Represents the point on the value axis where the category axis crosses it.
CrossType { get; set; }Represents the CrossType on the specified axis where the other axis crosses.
CustomDisplayUnit { get; set; }Specifies a custom value for the display unit.
CustomUnit { get; set; }(Obsolete.) Specifies a custom value for the display unit.
CustUnit { get; set; }(Obsolete.) Specifies a custom value for the display unit.
DisplayUnit { get; set; }Represents the unit label for the specified axis.
DisplayUnitLabel { get; }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.
HasMultiLevelLabels { get; set; }Indicates whether the labels shall be shown as multi level.
IsAutomaticMajorUnit { get; set; }Indicates whether the major unit of the axis is automatically assigned.
IsAutomaticMaxValue { get; set; }Indicates whether the max value is automatically assigned.
IsAutomaticMinorUnit { get; set; }Indicates whether the minor unit of the axis is automatically assigned.
IsAutomaticMinValue { get; set; }Indicates whether the min value is automatically assigned.
IsAutoTickLabelSpacing { get; set; }Indicates whether the spacing of tick label is automatic
IsDisplayUnitLabelShown { get; set; }Represents if the display unit label is shown on the specified axis.
IsLogarithmic { get; set; }Represents if the value axis scale type is logarithmic or not.
IsPlotOrderReversed { get; set; }Represents if Microsoft Excel plots data points from last to first.
IsVisible { get; set; }Represents if the axis is visible.
LogBase { get; set; }Represents the logarithmic base. Default value is 10.Only applies for Excel2007.
MajorGridLines { get; }Represents major gridlines on a chart axis.
MajorTickMark { get; set; }Represents the type of major tick mark for the specified axis.
MajorUnit { get; set; }Represents the major units for the axis.
MajorUnitScale { get; set; }Represents the major unit scale for the category axis.
MaxValue { get; set; }Represents the maximum value on the value axis.
MinorGridLines { get; }Represents minor gridlines on a chart axis.
MinorTickMark { get; set; }Represents the type of minor tick mark for the specified axis.
MinorUnit { get; set; }Represents the minor units for the axis.
MinorUnitScale { get; set; }Represents the major unit scale for the category axis.
MinValue { get; set; }Represents the minimum value on the value axis.
TickLabelPosition { get; set; }Represents the position of tick-mark labels on the specified axis.
TickLabels { get; }Returns a TickLabels object that represents the tick-mark labels for the specified axis.
TickLabelSpacing { get; set; }Represents the number of categories or series between tick-mark labels. Applies only to category and series axes.
TickMarkSpacing { get; set; }Returns or sets the number of categories or series between tick marks. Applies only to category and series axes.
Title { get; }Gets the axis’ title.

Methods

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

Examples

namespace AsposeCellsExamples
{
    using Aspose.Cells;
    using Aspose.Cells.Charts;
    using System;
    using System.Drawing;

    public class AxisDemo
    {
        public static void AxisExample()
        {
            // Instantiating a Workbook object
            Workbook workbook = new Workbook();
            // Adding a new worksheet to the Workbook object
            int sheetIndex = workbook.Worksheets.Add();
            // Obtaining the reference of the newly added worksheet by passing its sheet index
            Worksheet worksheet = workbook.Worksheets[sheetIndex];
            // Adding sample values to cells
            worksheet.Cells["A1"].PutValue(50);
            worksheet.Cells["A2"].PutValue(100);
            worksheet.Cells["A3"].PutValue(150);
            worksheet.Cells["B1"].PutValue(4);
            worksheet.Cells["B2"].PutValue(20);
            worksheet.Cells["B3"].PutValue(50);
            // Adding a chart to the worksheet
            int chartIndex = worksheet.Charts.Add(ChartType.Column, 5, 0, 25, 5);
            // Accessing the instance of the newly added chart
            Chart chart = worksheet.Charts[chartIndex];
            // Adding NSeries (chart data source) to the chart ranging from "A1" cell to "B3"
            chart.NSeries.Add("A1:B3", true);

            // Accessing the value axis of the chart
            Axis valueAxis = chart.ValueAxis;
            // Setting properties of the value axis
            valueAxis.IsAutomaticMinValue = false;
            valueAxis.MinValue = 0;
            valueAxis.IsAutomaticMaxValue = false;
            valueAxis.MaxValue = 200;
            valueAxis.IsAutomaticMajorUnit = false;
            valueAxis.MajorUnit = 25;
            valueAxis.IsAutomaticMinorUnit = false;
            valueAxis.MinorUnit = 5;
            valueAxis.MajorTickMark = TickMarkType.Outside;
            valueAxis.MinorTickMark = TickMarkType.Inside;
            valueAxis.TickLabelPosition = TickLabelPositionType.NextToAxis;
            valueAxis.CrossAt = 0;
            valueAxis.CrossType = CrossType.Minimum;
            valueAxis.IsLogarithmic = false;
            valueAxis.IsPlotOrderReversed = false;
            valueAxis.AxisBetweenCategories = true;
            valueAxis.TickLabelSpacing = 1;
            valueAxis.IsAutoTickLabelSpacing = true;
            valueAxis.TickMarkSpacing = 1;
            valueAxis.DisplayUnit = DisplayUnitType.None;
            valueAxis.IsDisplayUnitLabelShown = false;
            valueAxis.CategoryType = CategoryType.AutomaticScale;
            valueAxis.BaseUnitScale = TimeUnit.Months;
            valueAxis.MajorUnitScale = TimeUnit.Months;
            valueAxis.MinorUnitScale = TimeUnit.Months;
            valueAxis.IsVisible = true;
            valueAxis.HasMultiLevelLabels = false;

            // Accessing the category axis of the chart
            Axis categoryAxis = chart.CategoryAxis;
            // Setting properties of the category axis
            categoryAxis.IsAutomaticMinValue = false;
            categoryAxis.MinValue = 0;
            categoryAxis.IsAutomaticMaxValue = false;
            categoryAxis.MaxValue = 3;
            categoryAxis.IsAutomaticMajorUnit = false;
            categoryAxis.MajorUnit = 1;
            categoryAxis.IsAutomaticMinorUnit = false;
            categoryAxis.MinorUnit = 0.5;
            categoryAxis.MajorTickMark = TickMarkType.Outside;
            categoryAxis.MinorTickMark = TickMarkType.Inside;
            categoryAxis.TickLabelPosition = TickLabelPositionType.NextToAxis;
            categoryAxis.CrossAt = 0;
            categoryAxis.CrossType = CrossType.Minimum;
            categoryAxis.IsLogarithmic = false;
            categoryAxis.IsPlotOrderReversed = false;
            categoryAxis.AxisBetweenCategories = true;
            categoryAxis.TickLabelSpacing = 1;
            categoryAxis.IsAutoTickLabelSpacing = true;
            categoryAxis.TickMarkSpacing = 1;
            categoryAxis.DisplayUnit = DisplayUnitType.None;
            categoryAxis.IsDisplayUnitLabelShown = false;
            categoryAxis.CategoryType = CategoryType.AutomaticScale;
            categoryAxis.BaseUnitScale = TimeUnit.Months;
            categoryAxis.MajorUnitScale = TimeUnit.Months;
            categoryAxis.MinorUnitScale = TimeUnit.Months;
            categoryAxis.IsVisible = true;
            categoryAxis.HasMultiLevelLabels = false;

            // Saving the Excel file
            workbook.Save("AxisExample.xlsx");
            workbook.Save("AxisExample.pdf");
        }
    }
}

See Also