GridLine on top of a Bar Chart in Mathematica
Asked Answered
N

2

8

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 -> {None, {4}}, 
         GridLinesStyle -> Directive[Orange, Thick]]

enter image description here

Nicotinism answered 24/8, 2011 at 14:47 Comment(0)
E
15

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}]

enter image description here

(this should work for any graphic.)

Emmuela answered 24/8, 2011 at 14:56 Comment(9)
At Brett, wonderful, thank You ! For some reason @Brett, makes Brett and @ disappear.Nicotinism
Is this documented? I don't think I've come across that before.Kepner
It appears that there is also a Graphics option Method -> {"AxesInFront" -> True} See here for Mathgroup discussion by David Park. Never heard of either myself.Bradfordbradlee
@500, the @ and Brett disappears because it is unambiguous as to who your referring to.Ethelstan
I must second the question of whether it is documented or not.Ethelstan
Method isn't documented as an option for either Graphics or BarChart in the version 8 documentation - time to add to my [#7087649.Presocratic
@Verbeia: Method is indeed a documented option of Graphics (and thus of BarChart.) Specifically it's listed in the options table under Notes, although neither BarChart nor Graphics contains examples of its use.Emmuela
Ah - I see, but it's not in the list of options given in the documentation under the "Options" heading. I'll revise the question accordingly.Presocratic
@Nicotinism see here for a possible explanation of the disappearing @-username. Personally, I preferred things as they were.Bradfordbradlee
P
4

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]

enter image description here

Presocratic answered 24/8, 2011 at 21:4 Comment(1)
@Vebeia,Thank you for your attention.Nicotinism

© 2022 - 2024 — McMap. All rights reserved.