Hi,
I am using evaluation version of Aspose.Slides for Java 16.8.0.0.
I am trying to add a chart to the chart placeholder using the following code. However, it does not
insert the chart within the placeholder, rather it places the chart using the coordinates passed on
the top of the placeholder and not inside.
for (IShape shape : slide.getShapes()) {
if (shape.getPlaceholder() != null && shape.getPlaceholder().getType() == PlaceholderType.Chart) {
final IChart chart = slide.getShapes().addChart(ChartType.ClusteredColumn, 50, 50, 300, 300);
chart.addPlaceholder(shape.getPlaceholder());
break;
}
}
Do you have a sample code to
1. Place chart inside the chart placeholder
2. Stretch the chart to fit the placeholder dimensions
3. Remove text (Click icon to add chart) and chart icon from the chart placeholder.
I have attached sample template and the output of the PPT for your reference.
Thanks
Giri
Hi Giri,
I have observed your requirements. We will get back to you with feedback soon.
Best Regards,
Hi Giri,
I have observed your requirement. Actually, the Placeholder is a shape without a graphics representation and with a placeholder type. Placeholder is not a chart or a table. PowerPoint replaces placeholder by a specific shape on a customer’s demand. During this replacement PowerPoint creates a completely new shape instead of placeholder. In the same way, the you also need to create a new shape (chart, table or Autoshape) instead of a placeholder. You have done right by adding new shape and you have to do additional by removing the existing old placeholder shape as well.
Many Thanks,
Thanks Mudassir.
I got this working now. I still use a chart placeholder to mark the position of the chart in the template slide and use its dimensions to create new chart and delete the placeholder as you advised. Here is a sample code. This code meets all my 3 requirements.
<pre style=“background-color: rgb(255, 255, 255); font-family: “Courier New”; font-size: 9pt;”><pre style=“font-family: “Courier New”; font-size: 9pt;”>IShape chartPlaceHolderShape = null;
// Find a chart placeholder
for (IShape shape : slide.getShapes()) {
if (shape.getPlaceholder() != null && shape.getPlaceholder().getType() == PlaceholderType.Chart) {
chartPlaceHolderShape = shape;
break;
}
}
<pre style=“background-color: rgb(255, 255, 255); font-family: “Courier New”; font-size: 9pt;”>if (chartPlaceHolderShape != null) {
// Replace placeholder with chart
final IChart chart = slide.getShapes()
.addChart(ChartType.ClusteredColumn, chartPlaceHolderShape.getX(), chartPlaceHolderShape.getY(),
chartPlaceHolderShape.getWidth(), chartPlaceHolderShape.getHeight());
slide.getShapes().remove(chartPlaceHolderShape);
}
Thanks very much. We are buying the license shortly as my evaluation is successful.
Giri
Hi Giri,
It’s good to know things are working on your end. Thank you very much for your growing interest in Aspose.Slides. Please feel free to share if there is any further inquiry in this regard.
Many Thanks,