Formatting of horizontal axis is not working

Hi,

I have created a chart with no data added, I have applied the format for horizontal axis is as below
chart.getAxes().getHorizontalAxis().setCategoryAxisType(2);
chart.getAxes().getHorizontalAxis().setNumberFormat(“MMM-YY”);

Whenever I create slide with chart, it shows format as expected ( eg: JAN-00)

With the same formatting code, I have added some sample data to the chart.
After adding data , horizontal axis formatting is not retained , now it comes on chart as “2014-03-02” . When I select format axis on chart axes, I could see that axis type is “Text axis”.

Requirement :

whenever I add data as " 2014-03-21" to underlying chart work book , I need it to be displayed on chart’s horizontal axes as “Mar-14” .
Please help me.

Regards,
Ashok.

Hi Ashok,


I have observed your requirements and request you to please share working sample java file, source presentation, generated presentation and desired output. I will investigate the requirement on my end once requested information will be shared by you.

Best Regards,

Hi Adnan,

Thanks for responding.
I will not be able to share source java files as my organization doesn’t allow employees to upload any file ( not just company related file ). Actually uploading is blocked for third party websites.
please let me know any other possibilities that might be helpful in getting your help

Hi Ashok,

I have observed the comments shared by you. Unfortunately, without provision of requested information, I may not be able to understand the issue properly and help you to rectify the issue on your end. However, I suggest you to please visit documentation link 1 and link 2 for your kind reference. In the shared links, you will find sample codes for setting number formats for chart axis as well as formatting different chart entities. If there is still an issue then please share a working example using dummy data but reproducing issue on your end. We will refer that on our end to help you out.

Best Regards,

Hi Adnan,

can you please share link or any example to change the format for Horizontal axis / category format. In the link1 , it shows to change the values of Y-Axis or series data points.
But I wanted to change format for category values.

Hi Ashok,

I regret to share that without provision of requested information and working sample code, I may not proceed further with my investigation and helping you further. However, I request you to please visit the thread link 1 and link 2:
https://forum.aspose.com/t/how-to-pass-time-format-to-a-chart/14561
for your reference as well. I hope this will be helpful.

Best Regards,

Hi Adnan,

None of the links you have shared has helped me in solving my issue.
If possible, can you please help sharing an example where category/X axes has date values .

Regards,
Ashok.

Hi Ashok,

I have observed your requirements and like to share that Aspose.Slides offers to set the preset format for chart data cell. You may set the preset format and add date value to serve the purpose on your end.

public static void setPresetNumber()
{

//Instantiate the presentation//Instantiate the presentation
Presentation pres = new Presentation();

//Access the first presentation slide
ISlide slide = pres.getSlides().get_Item(0);

//Adding a defautlt clustered column chart
IChart chart = slide.getShapes().addChart(ChartType.ClusteredColumn, 50, 50, 500, 400);

//Accessing the chart series collection
IChartSeriesCollection series = chart.getChartData().getSeries();
IChartCategoryCollection categories = chart.getChartData().getCategories();

//Setting the preset number format
//Traverse through every chart series
for (IChartSeries ser : series)
{
//Traverse through every data cell in series
for (IChartDataPoint cell : ser.getDataPoints())
{
//Setting the number format
cell.getValue().getAsCell().setPresetNumberFormat((byte)17); //mmm-yy
}
}

for (IChartCategory cat : categories)
{
//Setting the number format
cat.getAsCell().setPresetNumberFormat((byte)17); //mmm-yy
}


//Saving presentation
pres.save(path+“PresetNumberFormat.pptx”, SaveFormat.Pptx);

}

If there is still an issue then only option available is that you may please share the working sample code reproducing issue on your end along with source presentation, generated presentation and desired output presentation. On provision of requested information we will be more than happy to resolve the issue incurring on your end. Without provision of requested information it is unfortunately not possible for us to understand root cause of the issue. I hope this will understandable and I will be looking forward to receive positive feedback from your side in this regard.

Many Thanks,