# Configure Chart Axis

DsExcel allows you to configure the chart axis using the axis title, gridlines, display unit label, and tick labels. Learn more in DsExcel docs.

## Content

DsExcel Java provides you with several options that help you in configuring chart axis.
The following axes elements in the chart inserted in your spreadsheet are customizable:

* [Axis title](/document-solutions/java-excel-api/docs/online/Features/UseChart/CustomizeChartObjects/AxisAndOtherLines/Configure_Chart_Axis#axis-title)
* [Gridlines](/document-solutions/java-excel-api/docs/online/Features/UseChart/CustomizeChartObjects/AxisAndOtherLines/Configure_Chart_Axis#gridlines)
* [Display unit label](/document-solutions/java-excel-api/docs/online/Features/UseChart/CustomizeChartObjects/AxisAndOtherLines/Configure_Chart_Axis#display-unit-label)
* [Tick labels](/document-solutions/java-excel-api/docs/online/Features/UseChart/CustomizeChartObjects/AxisAndOtherLines/Configure_Chart_Axis#tick-labels)

## Axis title

Users can set custom style for the axis title using the [getAxisTitle](/document-solutions/java-excel-api/api/online/com/grapecity/documents/excel/drawing/IAxis.html#getAxisTitle) of the [IAxis](/document-solutions/java-excel-api/api/online/com/grapecity/documents/excel/drawing/IAxis.html) interface.
In order to configure the layout of the title of the chart axis, refer to the following example code.

```Java
IShape shape = worksheet.getShapes().addChart(ChartType.ColumnClustered, 250, 20, 360, 230);
worksheet.getRange("A1:D6").setValue(new Object[][] { { null, "S1", "S2", "S3" }, { "Item1", 10, 25, 25 },
        { "Item2", 51, 36, 27 }, { "Item3", 52, 85, 30 }, { "Item4", 22, 65, 65 }, { "Item5", 23, 69, 69 } });
shape.getChart().getSeriesCollection().add(worksheet.getRange("A1:D6"), RowCol.Columns, true, true);
        
IAxis category_axis = shape.getChart().getAxes().item(AxisType.Category);
category_axis.setHasTitle(true);
category_axis.getAxisTitle().setText("CategoryAxisTitle");
category_axis.getAxisTitle().getFont().setSize(18);
category_axis.getAxisTitle().getFont().getColor().setRGB(Color.GetOrange());
```

You can also set the direction of the axis title to horizontal, vertical, rotated (to 90 or 270 degree), and stacked (with text reading left-to-right or right to left). The **setDirection** method in [IAxisTitle](/document-solutions/java-excel-api/api/online/com/grapecity/documents/excel/drawing/IAxisTitle.html) and IAxisTitle.[ITextFrame](/document-solutions/java-excel-api/api/online/com/grapecity/documents/excel/drawing/ITextFrame.html) interfaces allows you to set the direction of the axis title using [TextDirection](/document-solutions/java-excel-api/api/online/com/grapecity/documents/excel/drawing/TextDirection.html) enumeration.
Refer to the following example code to set the axis title direction to stacked:

```Java
// Create chart.
shape.getChart().getSeriesCollection().add(worksheet.getRange("A1:D6"), RowCol.Columns, true, true);

IAxis category_axis = shape.getChart().getAxes().item(AxisType.Category);

// Display the axis title.
category_axis.setHasTitle(true);

// Set the name of axis title.
category_axis.getAxisTitle().setText("Category");

// Set direction of axis title to stacked.
category_axis.getAxisTitle().getTextFrame().setDirection(TextDirection.Stacked);

// OR
category_axis.getAxisTitle().setDirection(TextDirection.Stacked);
```

DsExcel also allows you to configure the text angle of axis titles by using the **setOrientation** method of IAxisTitle interface.
Refer to the following example code to set the text angle of the axis title:

```Java
// Create chart.
shape.getChart().getSeriesCollection().add(worksheet.getRange("A1:D6"), RowCol.Columns, true, true);

IAxis category_axis = shape.getChart().getAxes().item(AxisType.Category);

// Display the axis title.
category_axis.setHasTitle(true);

// Set the name of axis title.
category_axis.getAxisTitle().setText("Category");

// Set axis title orientation to 45 degrees.
category_axis.getAxisTitle().setOrientation(45);
```

The direction and orientation of the axis title can also be exported or imported into a JSON or PDF document.

> !type=note
> **Note**: The setOrientation method only applies if the value of setDirection method is Horizontal.

## Gridlines

Users can also customize the style of major and minor gridlines in a chart axis using the [getMajorGridlines](/document-solutions/java-excel-api/api/online/com/grapecity/documents/excel/drawing/IAxis.html#getMajorGridlines) method, [getMinorGridlines](/document-solutions/java-excel-api/api/online/com/grapecity/documents/excel/drawing/IAxis.html#getMinorGridlines) method, [setHasMajorGridlines](/document-solutions/java-excel-api/api/online/com/grapecity/documents/excel/drawing/IAxis.html#setHasMajorGridlines) method and [setHasMinorGridlines](/document-solutions/java-excel-api/api/online/com/grapecity/documents/excel/drawing/IAxis.html#setHasMinorGridlines) method of the [IAxis](/document-solutions/java-excel-api/api/online/com/grapecity/documents/excel/drawing/IAxis.html) interface.
In order to set major and minor gridlines' style, refer to the following example code.

```Java
IShape shape = worksheet.getShapes().addChart(ChartType.ColumnClustered, 250, 20, 360, 230);
worksheet.getRange("A1:D6").setValue(
        new Object[][] { { null, "S1", "S2", "S3" }, { "Item1", 10, 25, 25 }, { "Item2", -51, -36, 27 },
                { "Item3", 52, -85, -30 }, { "Item4", 22, 65, 65 }, { "Item5", 23, 69, 69 } });
shape.getChart().getSeriesCollection().add(worksheet.getRange("A1:D6"), RowCol.Columns, true, true);

IAxis value_axis = shape.getChart().getAxes().item(AxisType.Value);
value_axis.setHasMajorGridlines(true);
value_axis.setHasMinorGridlines(true);
value_axis.getMajorGridlines().getFormat().getLine().getColor().setRGB(Color.GetGray());
value_axis.getMajorGridlines().getFormat().getLine().setWeight(1);
value_axis.getMinorGridlines().getFormat().getLine().getColor().setRGB(Color.GetLightGray());
value_axis.getMinorGridlines().getFormat().getLine().setWeight(0.75);
value_axis.setMajorUnit(40);
value_axis.setMinorUnit(8);
value_axis.getMinorGridlines().getFormat().getLine().setStyle(LineStyle.ThickThin);
```

## Display unit label

Users can customize the display unit labels in the chart axis via configuring the display unit for the axis along with its label style using the [setDisplayUnit](/document-solutions/java-excel-api/api/online/com/grapecity/documents/excel/drawing/IAxis.html#setDisplayUnit) method, [getDisplayUnitLabel](/document-solutions/java-excel-api/api/online/com/grapecity/documents/excel/drawing/IAxis.html#getDisplayUnitLabel) method, [setDisplayUnitCustom](/document-solutions/java-excel-api/api/online/com/grapecity/documents/excel/drawing/IAxis.html#setDisplayUnitCustom) method and [setHasDisplayUnitLabel](/document-solutions/java-excel-api/api/online/com/grapecity/documents/excel/drawing/IAxis.html#setHasDisplayUnitLabel) method of the [IAxis](/document-solutions/java-excel-api/api/online/com/grapecity/documents/excel/drawing/IAxis.html) interface.
In order to configure display unit for the axis and set custom label style, refer to the following example code.

```Java
IShape shape = worksheet.getShapes().addChart(ChartType.ColumnClustered, 250, 20, 360, 230);
worksheet.getRange("A1:D6").setValue(
        new Object[][] { { null, "S1", "S2", "S3" }, { "Item1", 10, 25, 25 }, { "Item2", -51, -36, 27 },
                { "Item3", 52, -85, -30 }, { "Item4", 22, 65, 65 }, { "Item5", 23, 69, 69 } });
shape.getChart().getSeriesCollection().add(worksheet.getRange("A1:D6"), RowCol.Columns, true, true);

IAxis value_axis = shape.getChart().getAxes().item(AxisType.Value);
value_axis.setDisplayUnit(DisplayUnit.Custom);
value_axis.setDisplayUnitCustom(100);
value_axis.setHasDisplayUnitLabel(true);
value_axis.getDisplayUnitLabel().getFont().getColor().setRGB(Color.GetCornflowerBlue());
value_axis.getDisplayUnitLabel().getFormat().getFill().getColor().setRGB(Color.GetOrange());
value_axis.getDisplayUnitLabel().getFormat().getLine().getColor().setRGB(Color.GetCornflowerBlue());
```

## Tick labels

Users can customize tick labels in chart axis via configuring the position and layout of the tick-mark labels using the [setTickLabelPosition](/document-solutions/java-excel-api/api/online/com/grapecity/documents/excel/drawing/IAxis.html#setTickLabelPosition) method, [getTickLabels](/document-solutions/java-excel-api/api/online/com/grapecity/documents/excel/drawing/IAxis.html#getTickLabels) method, [setTickLabelSpacing](/document-solutions/java-excel-api/api/online/com/grapecity/documents/excel/drawing/IAxis.html#setTickLabelSpacing) method of the [IAxis](/document-solutions/java-excel-api/api/online/com/grapecity/documents/excel/drawing/IAxis.html) interface.
Refer to the following example code to configure the tick mark label's position and layout.

```Java
shape.getChart().getSeriesCollection().add(worksheet.getRange("A1:D6"), RowCol.Columns, true, true);
        
IAxis value_axis = shape.getChart().getAxes().item(AxisType.Value);
IAxis category_axis = shape.getChart().getAxes().item(AxisType.Category);

category_axis.setTickLabelPosition(TickLabelPosition.NextToAxis);
category_axis.setTickLabelSpacing(2);
category_axis.getTickLabels().getFont().getColor().setRGB(Color.GetDarkOrange());
category_axis.getTickLabels().getFont().setSize(12);
category_axis.getTickLabels().setNumberFormat("#,##0.00");
value_axis.getTickLabels().setNumberFormat("#,##0;[Red]#,##0");
```

You can also set the direction of the tick labels to horizontal, vertical, rotated (to 90 or 270 degree), and stacked (with text reading left-to-right or right to left). The [setDirection](/document-solutions/java-excel-api/api/online/com/grapecity/documents/excel/drawing/ITickLabels.html#setDirection) method in [ITickLabels](/document-solutions/java-excel-api/api/online/com/grapecity/documents/excel/drawing/ITickLabels.html) interface allows you to set the direction of the axis title using [TextDirection](/document-solutions/java-excel-api/api/online/com/grapecity/documents/excel/drawing/TextDirection.html) enumeration.
Refer to the following example code to set the vertical tick labels:

```Java
// Create chart.
shape.getChart().getSeriesCollection().add(worksheet.getRange("A1:D6"), RowCol.Columns, true, true);

// Set category axis.
var categoryAxis = shape.getChart().getAxes().item(AxisType.Category);

// Set category tick labels to vertical.
categoryAxis.getTickLabels().setDirection(TextDirection.Vertical);
```

DsExcel also allows you to configure the text angle of tick-mark labels by using the [setOrientation](/document-solutions/java-excel-api/api/online/com/grapecity/documents/excel/drawing/ITickLabels.html#setOrientation) method of ITickLabels interface.
Refer to the following example code to set the text angle of tick mark label:

```Java
shape.getChart().getSeriesCollection().add(worksheet.getRange("A1:D6"), RowCol.Columns, true, true);
IAxis category_axis = shape.getChart().getAxes().item(AxisType.Category);
    
//config tick label's angle
category_axis.getTickLabels().setOrientation(45);

//save to an excel file
workbook.save("configtickmarklabelangle.xlsx");
```

The direction and orientation of the tick labels can also be exported or imported into a JSON or PDF document.

> !type=note
> **Note**: The setOrientation method only applies if the value of setDirection method is Horizontal.