Change the color of only one of the bars/columns of the graph generated in PPTX - Apache Poi

Asked

Viewed 45 times

0

I’m working with the Apache Poi v4.1.2 in the Java for file generation .pptx, slide display on PowerPoint. I’m basically using the Apache Poi to generate slides with graphics, so far so good, I am able to generate the slides with the graphics and everything, but there is a demand for me that is the possibility of changing the colors of the bars/ columns of the graph to customized colors. I already got him to change the colors of the chart by série, i.e., all bars of "such" série has the color changed to a custom one, the problem is q have cases where I need to change the color of a single bar/column, ie change the color by category maybe or something more specific, but I could not find a way to do this, nor in my researches I found something that helps me, someone can give me a light and help me?

q code I’m using for custom color settar:

final XDDFSolidFillProperties fill = new XDDFSolidFillProperties(XDDFColor.from(new byte[] { 0, 0, 0 })); // usando a cor preta como exemplo
final XDDFChartData.Series series = this.getElementGraph().getSeries(0); // pegando a primeira série
// o this.getElementGraph() retorna um XDDFChartData
XDDFShapeProperties properties = series.getShapeProperties();
if (properties == null) {
    properties = new XDDFShapeProperties();
}
properties.setFillProperties(fill);
series.setShapeProperties(properties);

1 answer

1

In your code above, you can replace the lines:

XDDFShapeProperties properties = series.getShapeProperties();
if (properties == null) {
    properties = new XDDFShapeProperties();
}
properties.setFillProperties(fill);
series.setShapeProperties(properties);

by a single line:

series.setFillProperties(fill);

since your code reproduces the above method code.

As to your question, the possibility of individually changing a certain point of the graph was missing, in fact, until today.

It will be possible once the version with the suggested change is published on https://github.com/apache/poi/pull/228

It will be possible to call it that:

XDDFDataPoint point = series.getDataPoint(2);
point.setFillProperties(fill);

It will also be possible to change the marker in case ScatterChart or LineChart, as well as the explosion in the event of PieChart.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.