Hello ,
I am using aspose slides for java in order to generate a powerpoint from an excel sheet .
I need to modify the displayed categories ( rows ) of an histogram according to some criteria .
Below a histogram that I would to modify :
Sans titre1.png (2.5 KB)
I set the values of the categories I want to hide to “null” , the cells became empty but I still have a white space in my chart . I tried chart.getChartData().getCategories().remove(chart.getChartData().getCategories().get_Item(4)) but it doesn’t work .
In other words , I want to hide empty cells from the chart .
Is there any method to do this by using Aspose slides for java ?
Just a detail : I’m using a trial version of aspose.slides in order to test its functionlities and i’m planning to purchase the product soon .
Thank you .
Best regards
@mohameddh,
I have observed your comments. Can you please share sample files and source code so that we may further investigate to help you out.
Thank you for the quick answer ,
What I need to do is quite simple : I want to delete some bars from an histogram .
I attached two files : the first one is what I have as a chart and the second one is what I am trying to obtain ( delete 3 colnames from the chart ) .
Thank you very much for your cooperation .
Best regards
Existing.PNG (27.7 KB)
target.PNG (24.0 KB)
@mohameddh,
I have observed your requirements and suggest you to please try using following sample code on your end to serve the purpose. For your kind reference, I have also attached the source presentation as well.
public static void TestRemoveCategories()
{
String path = @"C:\\Aspose Data\\";
Presentation pres = new Presentation(path + "RemoveCats.pptx");
ISlide slide = pres.Slides[0];
IChart chart = (IChart)slide.Shapes[0];
IChartCategoryCollection categoryCollection = chart.ChartData.Categories;
IChartCategory cat = categoryCollection[categoryCollection.Count - 1];
categoryCollection.RemoveAt(categoryCollection.Count - 1);
categoryCollection.RemoveAt(categoryCollection.Count - 1);
categoryCollection.RemoveAt(categoryCollection.Count - 1);
chart.ChartData.SetRange("Sheet1!$A$1:$B$8");
pres.Save(path + "saved.pptx", Aspose.Slides.Export.SaveFormat.Pptx);
}
Aspose Data.zip (73.7 KB)
1 Like
I have tried the code but I encountred several problems :
- java does not recognize “pres.Slides[0]” so I changed it to "pres.getSlides().get_Item(0) " and it works , the same for slide.Shapes[0] .
2.I changed “categoryCollection[categoryCollection.Count - 1]” to “categoryCollection.get_Item(categoryCollection.size() - 1)” , because the first syntax does not work .
3.Java does not recognize “RemoveAt” , so I changed it to “categoryCollection.remove(categoryCollection.get_Item(categoryCollection.size() - 1));”
4.java does not recognize the function"SetRange"
I think that I am using an outdated version of Aspose or it is due to the fact that I am using a trial version .
.
@mohameddh,
Please try using following sample code using Aspose.Slides for Java 17.7 on your end.
public static void TestRemoveCategories()
{
String path = "C:\\Aspose Data\\";
Presentation pres = new Presentation(path + "RemoveCats.pptx");
ISlide slide = pres.getSlides().get_Item(0);
IChart chart = (IChart)slide.getShapes().get_Item(0);
IChartCategoryCollection categoryCollection = chart.getChartData().getCategories();
IChartCategory cat = categoryCollection.get_Item(categoryCollection.size() - 1);
categoryCollection.removeAt(categoryCollection.size() - 1);
categoryCollection.removeAt(categoryCollection.size() - 1);
categoryCollection.removeAt(categoryCollection.size() - 1);
chart.getChartData().setRange("Sheet1!$A$1:$B$8");
pres.save(path + "saved.pptx", SaveFormat.Pptx);
}
1 Like
It works perfectly, thank you very much for your help
Hello ,
I have another question regarding the chart formatting : is there any method to change the font size and the font type of the pourcentage labels ? ( values above the bars )
Many thanks in advance
@mohameddh,
I have observed your requirements and suggest you to please visit Formatting Chart Entities documentation link where by you will find the sample for formatting chart data labels. I hope this will be helpful.