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.
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;
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;
Change tick labels' position
chart.PrimaryCategoryAxis.TickLabelPosition = TickLabelPositionType.TickLabelPositionHigh;
Full Code:
using Spire.Presentation; using Spire.Presentation.Charts; namespace TickMarkLabel { class Program { static void Main(string[] args) { 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); } } }
Imports Spire.Presentation Imports Spire.Presentation.Charts Namespace TickMarkLabel Class Program Private Shared Sub Main(args As String()) 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) End Sub End Class End Namespace