Free Support Forum - aspose.com

Trying to set category axis to a Text axis

Hello,



I have just started using aspose an I have a question. I have been looking in the forum and google with no luck so far. Seems to be a pretty simple thing but just cannot figure out how to do it.




I am creating a chart based on data from 2 column. The chart which I want to create is going to be an Areastacked chart. (will be adding about 8 more columns with data and also adding lines at some point)






Column A contains all dates and time for a time period of 24 hours with a 1 sec interval.

Column B contains numeric values






I have made some code to generate this chart. The problem is that when the chart is created, I just see 1 number on the x-axis which is the start time I am assuming. What I want to display is all whole hours. (0,1,2,3,…22,23).






After creating the chart, if I manually open the excel file with the generated chart and change the x-axis Axis type from a “Automacially select base on data” to a “Text axis” then all data is show correctly as I would like on the chart. So my first question is, is it possible (and how) to change the Axis type to a Text Axis?






If not, what am I doing wrong?



Below is a snippit of the code:








Excel excel = new Workbook(“C:\somefile.xlsx”);

Worksheets sheet = excel.Worksheets[“Sheet1”];

Cells cells = excel.Worksheets[“Sheet1”].Cells;



charts = excel.Worksheets[“Sheet1”].Charts;

int chartIndex = charts.Add(ChartType.AreaStacked, 1, 3, 25, 20);

chart = charts[chartIndex];

chart.ValueAxis.TickLabels.NumberFormat = “0”;

chart.ValueAxis.MinValue = 30;

chart.ValueAxis.MaxValue = 110;



chart.NSeries.Add(“Sheet1!B2:B1441”, true);



chart.NSeries.CategoryData = “Sheet1!A2:A1441”;



chart.CategoryAxis.TickLabels.NumberFormat = “hh”;

chart.CategoryAxis.TickLabels.RotationAngle = 0;

chart.CategoryAxis.TickLabels.Font.Size = 8;

chart.CategoryAxis.TickLabelSpacing = 60;



//read somewehere that if you set the category type to Categroyscale it then sets it to a text axis but this does not worl

//chart.CategoryAxis.CategoryType = CategoryType.CategoryScale;



newFilename = “test.xlsx”;

excel.Save(newFilename, SaveFormat.Xlsx);

Hi,

Thanks for your posting and using Aspose.Cells.

Please create a simple chart of yours manually using Microsoft Excel and attach it here for our investigation. We will look into it and generate the similar chart using Aspose.Cells and provide you a sample code. You can then later look into it and work on it to make more complex chart of yours as per your requirements.

Thanks for your cooperation.

Attached are two file,



1. file (simple sample generate) is the file generated from Aspose.Net. You will need to change the categoryaxis to a “Text Axis” and that is how I want it.



2. Is a sample of an endresult with a chart and many columns created manually. This is how my end result should look like. If you want, use this and the first few columns.

Hi,

Thanks for your sample files and using Aspose.Cells.

I have checked your both charts and checked the category axis. I found both chart’s category axis number custom format is set to hh which looks fine to me. So where is the problem.

Please see the red highlighted area in the attached screenshots.

Could you please explain what do you mean by Text Axis. How to set or create Text Axis using Microsoft Excel.

hi again.



Okay so if you look at the first sample chart file.



1. Left-click and hightlight the x-axis. This will now mark the entire x-axis.

2.Right-click on the x-axis and select “Format axis”

3. In the Format chart axis ensire that “Axis options” is clicked and than the bar icon is selected.

4. Expand the Axis options “tree leaf”

5. Select “Text Axis” Radio button



You will now see the chart change to what I need it to look like.

I have done the above in the new attached file.

So my issue is that I need to do this programmatically.



/Imran

Hi Imran,

Thanks for your explanation and using Aspose.Cells.

You are already doing right thing. I have tested this issue with the following sample code. It loads your simple sample generate.xlsx excel file. Then it accesses the chart and sets the category axis’s category type to CategoryScale and then it sets the TickLabelSpacing to 60 and saves the workbook. The chart looks exactly same as required by you.

I have attached the output excel file generated by the code and screenshot showing the output chart for your reference.

I have tested this issue with the latest version: Aspose.Cells
for .NET v8.4.2.2
so please use the latest version to get the correct results.

C#


string filePath = @“D:\Downloads\simple+sample+generate.xlsx”;


Workbook workbook = new Workbook(filePath);


Worksheet worksheet = workbook.Worksheets[0];


Chart ch = worksheet.Charts[0];

ch.CategoryAxis.CategoryType = CategoryType.CategoryScale;

ch.CategoryAxis.TickLabelSpacing = 60;


workbook.Save(“output.xlsx”);


Hi Shakeel,



Hmmm, it is not working for me as intended. If you do not mind, I have attached my sample code and you can see that it does NOT change the x-axis as I would have expected.



Let me know your findings. I have removed license file, dlls, executables.

Hi,

Thanks for your sample project and using Aspose.Cells.

We were able to observe this issue after executing your sample project with your sample excel file using the latest version: Aspose.Cells
for .NET v8.4.2.2
. Aspose.Cells is unable to set the category axis to text axis.

We have logged this issue in our database for investigation. We will look into it and fix this issue. Once the issue is resolved or we have some other update for you, we will let you know asap.

This issue has been logged as

  • CELLSNET-43677 - Unable to set Category Axis to a Text Axis

Hi,

Thanks for using Aspose.Cells.

Please download and try the latest fix: Aspose.Cells
for .NET v8.4.2.7
and let us know your feedback.

The issues you have found earlier (filed as CELLSNET-43677) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.