Get and set chart dataPoint and label settings

We would like to change the Font Color of a data label in charts. Although when we set font color all other attributes get set back to default, like the font Size changes back from the original 16 points to 10. When we try to get the font size, we get “Null, NaN”. Is there any method to preserve other settings and only change the font color? We have the same problem with borders when we color e.g the bars in charts.

So, we try to get the data and after set again, but it is also dead end.

We use this methods with a simple bar chart:

1. Get Data label fontHeight is NULL
$dataLabel = $dataPoint->getLabel();
$fontHeight = $dataLabel->getTextFormat()->getPortionFormat()->getFontHeight();

2. Try this way run to error on createPortionFormatEffective
$textFrame = $dataLabel->getTextFrameForOverriding();
$portion = $textFrame
->getParagraphs()->get_Item(0)->getPortions()->get_Item(0);
$portion->createPortionFormatEffective();

Thank you for your helping!

Hi Weinacht,

I have observed your requirements and suggest you to please try using following sample code on your end to change the font color of data label.

iChartSeries.getLabels().get_Item(0).getDataLabelFormat().getTextFormat().getPortionFormat().getFillFormat().setFillType(FillType.Solid);
iChartSeries.getLabels().get_Item(0).getDataLabelFormat().getTextFormat().getPortionFormat().getFillFormat().getSolidFillColor().setColor(Color.yellow);
//For data point
iChartSeries.getDataPoints().get_Item(0).getLabel().getDataLabelFormat().getTextFormat().getPortionFormat().getFillFormat().setFillType(FillType.Solid);
iChartSeries.getDataPoints().get_Item(0).getLabel().getDataLabelFormat().getTextFormat().getPortionFormat().getFillFormat().getSolidFillColor().setColor(Color.yellow);

Moreover, when you use createPortionFormatEffective(), you reset the textual properties for portion to default theme. Therefore, I suggest you to please try using above alternate on your end to change the color of labels.

Many Thanks,
1 Like

Hi,

We tried the above sample code for data points.

//For data point
iChartSeries.getDataPoints().get_Item(0).getLabel().getDataLabelFormat().getTextFormat().getPortionFormat().getFillFormat().setFillType(FillType.Solid);
iChartSeries.getDataPoints().get_Item(0).getLabel().getDataLabelFormat().getTextFormat().getPortionFormat().getFillFormat().getSolidFillColor().setColor(Color.yellow);

Settings color of labels were succesfull.

However
other attributes for example fontHeight get set back to smaller size.

Many Thanks

Hi Weinacht,

It’s good to know things have worked on your end. As far as issue of font height getting changed, I request you to please first try using Aspose.Slides for Java 17.5 on your end and in case if there is still an issue then please share the working sample code, source and generated presentation reproducing the issue. I will be able to investigate the issue further on my end on provision of requested information.

Many Thanks,