GridLine on top of a Bar Chart in Mathematica
Is it possible to get a GridLine over a BartChart ? Gridlines draw it under and Mesh does not seem to work with BarChart.
BarChart[{Range[10], Range[10]},
ChartLayout -> "Stacked",
GridLines -&g开发者_如何学Got; {None, {4}},
GridLinesStyle -> Directive[Orange, Thick]]
This can be done via a method option:
BarChart[{Range[10], Range[10]}, ChartLayout -> "Stacked",
GridLines -> {None, {4}}, GridLinesStyle -> Directive[Orange, Thick],
Method -> {"GridLinesInFront" -> True}]
(this should work for any graphic.)
Your other option would be to draw the gridline explicitly with Epilog. This would be the solution if you wanted some gridlines (e.g. vertical ones) behind and some in front. I have added some other options in case you don't actually want the gridline to bleed over the axes.
BarChart[{Range[10], Range[10]}, ChartLayout -> "Stacked",
Epilog -> {Orange, Thick, Line[{{0, 4}, {3, 4}}]},
PlotRangeClipping -> True, PlotRangePadding -> 0]
精彩评论