Free Support Forum - aspose.com

Add labels in a chart

Hi,


I want to have some custom labels in a column chart. These will represent some percentages per category. Is it possible to share an example?

Hi,

Thanks for inquiring Aspose.Slides.

I have observed the requirements shared by you and suggest you to please try using the following sample code on your end for setting the custom chart data labels. You can calculate the percentage data of your chart and can show that by adding custom label.

public static void testChartLabels()
{
Presentation pres = new Presentation();
ISlide slide = pres.getSlides().get_Item(0);

IChart chart = slide.getShapes().addChart(ChartType.StackedColumn, 100, 100, 400, 400);
IChartSeries series = chart.getChartData().getSeries().get_Item(0);

IDataLabel lbl = series.getDataPoints().get_Item(0).getLabel();
lbl.getTextFrameForOverriding().setText ( “Red”);
lbl.getTextFrameForOverriding().getParagraphs().get_Item(0).getPortions().get_Item(0).getPortionFormat().getFillFormat().setFillType(FillType.Solid);
lbl.getTextFrameForOverriding().getParagraphs().get_Item(0).getPortions().get_Item(0).getPortionFormat().getFillFormat().getSolidFillColor().setColor(Color.RED);


lbl = series.getDataPoints().get_Item(1).getLabel();
lbl.getTextFrameForOverriding().setText ( “Blue”);
lbl.getTextFrameForOverriding().getParagraphs().get_Item(0).getPortions().get_Item(0).getPortionFormat().getFillFormat().setFillType(FillType.Solid);
lbl.getTextFrameForOverriding().getParagraphs().get_Item(0).getPortions().get_Item(0).getPortionFormat().getFillFormat().getSolidFillColor().setColor(Color.BLUE);


pres.save(“D:\Aspose Data\testChart.pptx”,SaveFormat.Pptx);

}

I hope the shared sample code will be helpful. Please share, if I may help you further in this regard.

Many Thanks,