We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Formatting Y Error Bars on Excel Chart

Hi,

I have the following snippet of code to format an Y Error Bar in a line series for a chart in Excel:

With chart1.NSeries(1).YErrorBar
.DisplayType = Charts.ErrorBarDisplayType.Both
.Type = Charts.ErrorBarType.FixedValue
.Amount = 1
End With

What property do I need to set, so the error bar has a horizontal line at the end like this:

image.png (819 Bytes)

I’ve tried a few different properties but can’t seem to find the correct one to set the End Style to “Cap”.
I thought it might be ShowMarkerTTop, but that doesn’t seem to do it.

Thanks!

@rlei

Thanks for using Aspose APIs.

Please use the Series.YErrorBar property for your needs. Here is the full runnable sample code for your reference. I have attached the output Excel file generated by the code as well as the screenshot.

Download Link:
Output-YErrorBar.zip (7.4 KB)

C#

Workbook workbook = new Workbook();

Cells cells = workbook.Worksheets[0].Cells;
cells["a1"].PutValue(2);
cells["a2"].PutValue(5);
cells["a3"].PutValue(3);
cells["a4"].PutValue(6);
cells["b1"].PutValue(4);
cells["b2"].PutValue(3);
cells["b3"].PutValue(6);
cells["b4"].PutValue(7);

cells["C1"].PutValue("Q1");
cells["C2"].PutValue("Q2");
cells["C3"].PutValue("Y1");
cells["C4"].PutValue("Y2");

int chartIndex = workbook.Worksheets[0].Charts.Add(ChartType.Column, 11, 0, 27, 10);

Chart chart = workbook.Worksheets[0].Charts[chartIndex];
chart.NSeries.Add("A1:B4", true);

chart.NSeries.CategoryData = "C1:C4";

for (int i = 0; i < chart.NSeries.Count; i++)
{
    Series aseries = chart.NSeries[i];
    aseries.YErrorBar.DisplayType = ErrorBarDisplayType.Minus;
    aseries.YErrorBar.Type = ErrorBarType.FixedValue;
    aseries.YErrorBar.Amount = 5;
}

workbook.Save("outputYErrorBar.xlsx");

Screenshot: