Read Axis Labels after Calculating the Chart
Contents
[
Hide
]
Possible Usage Scenarios
You can read axis labels of your chart after calculating its values using the Chart.Calculate() method. Please use the Axis.AxisLabels property for this purpose that will return the list of axis labels.
Read Axis Labels after Calculating the Chart
Please see the following sample code that loads the sample Excel file and reads the category axis labels of the chart in the first worksheet. It then prints the values of the axis labels on the console. Please see the console output of the sample code given below for a reference.
Sample Code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
//Load the Excel file containing chart | |
Workbook wb = new Workbook("sampleReadAxisLabelsAfterCalculatingTheChart.xlsx"); | |
//Access first worksheet | |
Worksheet ws = wb.Worksheets[0]; | |
//Access the chart | |
Chart ch = ws.Charts[0]; | |
//Calculate the chart | |
ch.Calculate(); | |
//Read axis labels of category axis | |
string[] lstLabels = ch.CategoryAxis.GetAxisTexts(); | |
//Print axis labels on console | |
Console.WriteLine("Category Axis Labels: "); | |
Console.WriteLine("---------------------"); | |
//Iterate axis labels and print them one by one | |
for (int i = 0; i < lstLabels.Length; i++) | |
{ | |
Console.WriteLine(lstLabels[i]); | |
} |
Console Output
Category Axis Labels:
---------------------
Iran
China
USA
Brazil
England