Mr MP
Mr MP

Reputation: 187

How to set the color of a barchart / barchartseries?

does anyone know how to set the color of a barchart / barchartseries in C# with openXml?

So far I have this:

foreach (var solidFill in barChartSeries.ChartShapeProperties.Descendants<SolidFill>().ToList())
        {
            solidFill.SchemeColor = ???
        }

Any idea how I can find out stuff like this myself. The documentation is really lacking.

Upvotes: 1

Views: 801

Answers (2)

Mr MP
Mr MP

Reputation: 187

With the help of @wp78de I found the solution:

When you create a new chart from code you have to add all the children in the constructor call:

new BarChartSeries(
    new ChartShapeProperties(
        new DocumentFormat.OpenXml.Drawing.SolidFill(
            new DocumentFormat.OpenXml.Drawing.RgbColorModelHex() { Val = "FFA9FF" }
        )
    )
);

Upvotes: 1

wp78de
wp78de

Reputation: 18950

You should be able to do it like this

x.Descendants<SolidFill>().First().SchemeColor = new SchemeColor(){ Val = SchemeColorValues.Accent2 };  

or that

x.Descendants<SolidFill>().First().RgbColorModelHex = new RgbColorModelHex() { Val = "FF0000" };

Upvotes: 1

Related Questions