gpt4 book ai didi

c# - 图表上的 Epplus 误差线

转载 作者:行者123 更新时间:2023-11-30 17:40:06 25 4
gpt4 key购买 nike

使用 Epplus,有没有办法在图表系列上添加误差线?

我没有发现任何关于 Epplus 能够在任何地方处理误差线的提及,而且在图表或任何单独的系列中似乎没有任何属性或方法表明您可以访问/创建误差线。

我正在尝试重新创建此图表,其中我只剩下误差线:

enter image description here

最佳答案

我已经提交了一个带有适当代码的拉取请求来处理 EPPlus 中的错误栏,但是如果有人需要在该请求被接受之前执行此操作,那么您可以使用以下代码手动执行此操作:

public static void AddErrorBars(ExcelBarChart chart, string customFullRange)
{
var nsmgr = new XmlNamespaceManager(chart.ChartXml.NameTable);
nsmgr.AddNamespace("c", "http://schemas.openxmlformats.org/drawingml/2006/chart");
nsmgr.AddNamespace("a", "http://schemas.openxmlformats.org/drawingml/2006/main");
nsmgr.AddNamespace("r", "http://schemas.openxmlformats.org/officeDocument/2006/relationships");
nsmgr.AddNamespace("c16r2", "http://schemas.microsoft.com/office/drawing/2015/06/chart");

XNamespace ns_c = "http://schemas.openxmlformats.org/drawingml/2006/chart";
XNamespace ns_a = "http://schemas.openxmlformats.org/drawingml/2006/main";

var xDoc = XDocument.Parse(chart.ChartXml.InnerXml);

var cSer = xDoc.XPathSelectElement("/c:chartSpace/c:chart/c:plotArea/c:barChart/c:ser", nsmgr);

cSer.Add(
new XElement(ns_c + "errBars",

new XElement(ns_c + "errBarType",
new XAttribute("val", "plus")
),

new XElement(ns_c + "errValType",
new XAttribute("val", "cust")
),

new XElement(ns_c + "noEndCap",
new XAttribute("val", "0")
),

new XElement(ns_c + "plus",
new XElement(ns_c + "numRef",
new XElement(ns_c + "f", customFullRange)
)
)
)
);

chart.ChartXml.LoadXml(xDoc.ToString());
}

关于c# - 图表上的 Epplus 误差线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34743539/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com