Using Epplus, is there a way to add error bars onto a chart series?
I haven't found any mention of Epplus being able to handle error bars anywhere and there doesn't seem to any property or method in either the chart or any individual series that indicates you can access/create error bars.
I'm trying to recreate this chart, of which all I have left are the error bars:

I have submitted a pull request with proper code to handle Error Bars in EPPlus, but if anyone needs to do it before that is accepted then you can do it manually with code such as:
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());
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With