Working with Tick-mark Labels on the Category Axis in C#, VB.NET

In charts, each category on the category axis is identified by a tick-mark label and separated from other categories by tick marks. The tick-mark label text comes from the name of the associated category and is usually placed next to the axis.

In this article, we will introduce how we can custom the tick-mark labels by changing the labels' position, rotating labels and specifying interval between labels in C#, VB.ENT.

Working with Tick-mark Labels on the Category Axis in C#, VB.NET

Figure 1 – Chart in Example File

To facilitate the introduction, we prepared a PowerPoint document that contains a column chart looks like the screenshot in Figure 1 and used below code to get the chart from the PowerPoint slide. Then we're able to custom the labels through the following ways.

Presentation ppt = new Presentation(@"C:\Users\Administrator\Desktop\ColumnChart.pptx",FileFormat.Pptx2013);
IChart chart = ppt.Slides[0].Shapes[0] as IChart;

Rotate tick labels

chart.PrimaryCategoryAxis.TextRotationAngle = 45;

Working with Tick-mark Labels on the Category Axis in C#, VB.NET

Specify interval between labels

To change the number of unlabeled tick marks, we must set IsAutomaticTickLabelSpacing property as false and change the TickLabelSpacing property to any number between 1 - 255.

chart.PrimaryCategoryAxis.IsAutomaticTickLabelSpacing = false;
chart.PrimaryCategoryAxis.TickLabelSpacing = 2;

Working with Tick-mark Labels on the Category Axis in C#, VB.NET

Change tick labels' position

chart.PrimaryCategoryAxis.TickLabelPosition = TickLabelPositionType.TickLabelPositionHigh;

Working with Tick-mark Labels on the Category Axis in C#, VB.NET

Full Code:

[C#]
Presentation ppt = new Presentation(@"C:\Users\Administrator\Desktop\ColumnChart.pptx",FileFormat.Pptx2013);
IChart chart = ppt.Slides[0].Shapes[0] as IChart;

//rotate tick labels
chart.PrimaryCategoryAxis.TextRotationAngle = 45;

//specify interval between labels
chart.PrimaryCategoryAxis.IsAutomaticTickLabelSpacing = false;
chart.PrimaryCategoryAxis.TickLabelSpacing = 2;

////change position
//chart.PrimaryCategoryAxis.TickLabelPosition = TickLabelPositionType.TickLabelPositionHigh;

ppt.SaveToFile("result.pptx", FileFormat.Pptx2013);
[VB.NET]
Dim ppt As New Presentation("C:\Users\Administrator\Desktop\ColumnChart.pptx", FileFormat.Pptx2013)
Dim chart As IChart = TryCast(ppt.Slides(0).Shapes(0), IChart)

'rotate tick labels
chart.PrimaryCategoryAxis.TextRotationAngle = 45

'specify interval between labels
chart.PrimaryCategoryAxis.IsAutomaticTickLabelSpacing = False
chart.PrimaryCategoryAxis.TickLabelSpacing = 2

'''/change position
'chart.PrimaryCategoryAxis.TickLabelPosition = TickLabelPositionType.TickLabelPositionHigh;

ppt.SaveToFile("result.pptx", FileFormat.Pptx2013)