Scatter chart x category axis date issue - Aspose cells C#

I m having 187 dates - A1:A187. 187 values-B1:B187. another 187 values - C1:C187. There are 2 series. 1st series has area chart and second series has scatter chart. But in x axis it shows some other values. But i need dates. How can i achieve this?

Can anyone solve my issue as soon as possible?

@jeevapreethi.j,

Could you please create your desired custom chart in MS Excel manually, save the Excel and post us to demonstrate your desired chart. We will check and devise some code segments to accomplish the task. Also, share your current sample (runnable) code (if you are using) to create your undesired chart in Excel file, we might update your code accordingly for your requirements.

PS. please zip the Excel file(s) or other files prior attaching.

Sample Excel.zip (9.7 KB)
Hi,

Thanks for your reply.

I have attached my excel. Please send me the sample code for the same. I will learn from it and implement it. Please share it as soon as possible.

@jeevapreethi.j,

Thanks for the sample file.

I have written a sample code to create your desired chart for your reference. I have used your sample file as template file for chart’s source data and created the custom chart accordingly. Please refer to the sample code and write your code by yourselves:
e.g.
Sample code:

        Workbook workbook = new Workbook("f:\\files\\SampleExcel.xlsx");

        //Get the first worksheet.
        Worksheet sheet = workbook.getWorksheets().get(0);

        //Create chart
        int chartIndex = sheet.getCharts().add(ChartType.AREA_STACKED, 22, 6, 43, 15);
        Chart chart = sheet.getCharts().get(chartIndex);

        //Set properties of nseries
        chart.getNSeries().add("Sheet1!B2:B121", true);
        chart.getNSeries().setCategoryData("Sheet1!A2:A121");

        chart.getNSeries().add("Sheet1!C2:C121", true);
        chart.getNSeries().get(1).setType(ChartType.SCATTER);
        chart.getNSeries().get(1).setXValues("Sheet1!A2:A121");
        
        //Set the max value of category axis
        chart.getCategoryAxis().setMaxValue(sheet.getCells().get("A121").getDateTimeValue());

        //Set the min value of category axis
        chart.getCategoryAxis().setMinValue(sheet.getCells().get("A2").getDateTimeValue());
        
        //Set the major unit attributes
        chart.getCategoryAxis().setCategoryType(CategoryType.AUTOMATIC_SCALE);
        chart.getCategoryAxis().setMajorUnitScale(TimeUnit.MONTHS);
        chart.getCategoryAxis().setMajorUnit(1);

        workbook.save("f:\\files\\out1.xlsx");

Hope, this helps a bit.

Hi,

I have attached my excel file and it’s code. I want x axis as dates. But it comes something else. Please look into it and let me know what changes need to be made.

20220723_093127.jpg (1.86 MB)

20220723_093049.jpg (3.55 MB)

20220723_093033.jpg (3.16 MB)

20220723_093203.jpg (1.06 MB)

20220723_093113.jpg (3.28 MB)

Hi,

Thanks for the sample code.

But it is not working for me. 20220723_082101.jpg (3.4 MB)
getNSeries() -I am getting method not found message. I m using aspose.cells version 8.1.2. What to do now?

The code segment I shared above was in Java. If you are using .NET, you may easily convert it or write in .NET code by yourselves. Please try using Chart.NSeries instead. But since you are using an older version of Aspose.Cells for .NET, so you need to upgrade to newer versions or latest APIs set. Please note, we cannot help you much to evaluate or provide code segments using older versions. We can only provide code segments using latest version or APIs set.

If you are are using an older version of Aspose.Cells for .NET, please upgrade to newer versions or use latest APIs set (e.g., Aspose.Cells for .NET v22.7). Please note, we cannot help you much to evaluate or provide code segments using older versions. We can only provide code segments using latest version or APIs set.

Thanks for your help.