有人知道如何使用openXml在C#中设置条形图/条形图的颜色吗?
到目前为止,我有这个:
foreach (var solidFill in barChartSeries.ChartShapeProperties.Descendants<SolidFill>().ToList())
{
solidFill.SchemeColor = ???
}
任何想法我自己都可以找到类似的东西。确实缺少文档。
答案 0 :(得分:1)
您应该能够像这样
x.Descendants<SolidFill>().First().SchemeColor = new SchemeColor(){ Val = SchemeColorValues.Accent2 };
或者那个
x.Descendants<SolidFill>().First().RgbColorModelHex = new RgbColorModelHex() { Val = "FF0000" };
答案 1 :(得分:0)
在@ wp78de的帮助下,我找到了解决方案:
从代码创建新图表时,必须在构造函数调用中添加所有子项:
new BarChartSeries(
new ChartShapeProperties(
new DocumentFormat.OpenXml.Drawing.SolidFill(
new DocumentFormat.OpenXml.Drawing.RgbColorModelHex() { Val = "FFA9FF" }
)
)
);