We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

How to Access the Number Category of An Axis

We are trying to access the number category (General, Date, Scientific, etc) of an axis to determine whether that axis should be rendered as a date. However, we have been unable to find the object property within the Aspose.Cells .NET API that would give us this information.

2020-06-24 16_20_57-.png (15.0 KB)

@airportyh,
You may use Series.DataLabels.NumberFormat property to get this information as demonstrated in the following sample code. Search for the comments //NOTE THIS LINE.

//Instantiating a Workbook object
Workbook workbook = new Workbook();
//Adding a new worksheet to the Excel 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 a sample value to "A1" cell
worksheet.Cells["A1"].PutValue(50);
//Adding a sample value to "A2" cell
worksheet.Cells["A2"].PutValue(100);
//Adding a sample value to "A3" cell
worksheet.Cells["A3"].PutValue(150);
//Adding a sample value to "B1" cell
worksheet.Cells["B1"].PutValue(4);
//Adding a sample value to "B2" cell
worksheet.Cells["B2"].PutValue(20);
//Adding a sample value to "B3" cell
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"
int index = chart.NSeries.Add("A1:B3", true);
var series = chart.NSeries[index];
Console.WriteLine(series.DataLabels.NumberFormat);//NOTE THIS LINE
//Set the max value of value axis
chart.ValueAxis.MaxValue = 200;
//Set the min value of value axis
chart.ValueAxis.MinValue = 0;
//Set the major unit
chart.ValueAxis.MajorUnit = 25;
//Category(X) axis crosses at the maxinum value.
chart.ValueAxis.CrossType = CrossType.Maximum;
//Set he number of categories or series between tick-mark labels. 
chart.CategoryAxis.TickLabelSpacing = 2;
//Saving the Excel file
workbook.Save("book1.xls");

Thank you! Didn’t know that existed. However, that still didn’t get us what we needed, because the axis we are looking at actually doesn’t belong to a series, but rather, it is the x axis of a scatter plot, which is a not tied to a series. Is there a way to access the same information for this?

2020-06-25 11_36_07-ChartExamples - Excel.png (30.2 KB)

@airportyh,

Please try using chart.CategoryAxis.TickLabels.NumberFormat attribute to get/set numbers formattings of the horizontal axis. Similarly you may try to use chart.ValueAxis.TickLabels.NumberFormat to get/set numbers formatting of the vertical axis.

If you still could not evaluate, kindly do provide your template Excel file containing your chart, we will check it soon.

PS. please zip the file prior attaching.

Thank you. I’ve looked into CategoryAxis.TickLabels and ValueAxis.TickLabels. They were not populated. Here I’ll upload a file I tested.ScatterExample.zip (12.0 KB)

@airportyh,
We have observed the issue and logged it for further investigation as:
CELLSNET-47447 - Number format of chart Axis cannot be retrieved

@airportyh,

We evaluated your issue further.
Please note, the number format is linked to data source if TickLabels.NumberFormatLinked is true and there is no number format settings in the tick labels, so the returned value is null now. We are afraid, we cannot support your needs soon for we have to get the number format from the linked data source.

The issue is still Open and once we have any update on it, we will let you know.

Okay, thank you for the work and thank you for letting me know.

@airportyh,

You are welcome.

@airportyh,
This is to inform you that we have fixed your issue (logged earlier as “CELLSNET-47447”) now. We will soon provide you the fixed version after performing QA and incorporating other enhancements and fixes.

Thank you very much!

@airportyh,
You are welcome.

@airportyh,
The issues you have found earlier (filed as CELLSNET-47447) have been fixed in Aspose.Cells for .NET v20.7. This message was posted using Bugs notification tool by ahsaniqbalsidiqui