Update: In versions 12.0+, you can use Around
:
BarChart[{{5, Around[5, 6], 5}, {2, Around[2, 3], 4}},
ChartLayout -> "Stacked"]
Original answer:
You can use a slightly modified version of the function errorBar
from howto/AddErrorBarsToChartsAndPlots (see also this Q/A):
ClearAll[errorBar]
errorBar[type_: "Rectangle"]:= Module[{error = If[#3 === {}, 0, #3[[1]]],
x0 = #[[1, 1]], x1 = #[[1, 2]], y1 = #[[2, 2]]},
{ChartElementData[type][##], {Black,
Line[{{{(x0 + x1) / 2, y1 - error}, {(x0+x1)/2 , y1 + error}},
{{1/4 (3 x0 + x1), y1 + error}, {1/4 (x0 + 3 x1), y1 + error}},
{{1/4 (3 x0 + x1), y1 - error}, {1/4 (x0 + 3 x1), y1 - error}}}]}}]&
and add the error information as metadata to the last element in each data group
BarChart[{{5, 5, 5 -> 7}, {2, 3, 4 -> 2}}, ChartLayout -> "Stacked",
ChartElementFunction -> {Automatic, Automatic, errorBar[]}]
Update: What if I want to put the error bar on the second rectangle out of the three?
You can post-process the BarChart
output to reorder groups of primitives so that the second rectangle (and the error lines associated with it) is at the end:
bc = BarChart[{{5, 5 -> 6, 5}, {2, 3 -> 2, 4}},
ChartLayout -> "Stacked",
ChartElementFunction -> {Automatic, errorBar[], Automatic}];
bc /. x : {{_Directive, __} ..} :> RotateLeft[x, 2]