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

500
  • 6,509
  • 8
  • 46
  • 80

2 Answers2

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.)

Sjoerd C. de Vries
  • 16,122
  • 3
  • 42
  • 94
Brett Champion
  • 8,497
  • 1
  • 27
  • 44
  • At Brett, wonderful, thank You ! For some reason @Brett, makes Brett and @ disappear. – 500 Aug 24 '11 at 15:00
  • 4
    Is this documented? I don't think I've come across that before. – Mr.Wizard Aug 24 '11 at 15:14
  • 1
    It appears that there is also a Graphics option `Method -> {"AxesInFront" -> True}` See [here](http://forums.wolfram.com/mathgroup/archive/2007/Aug/msg00164.html) for Mathgroup discussion by David Park. Never heard of either myself. – 681234 Aug 24 '11 at 15:46
  • @500, the @ and Brett disappears because it is unambiguous as to who your referring to. – rcollyer Aug 24 '11 at 15:50
  • 2
    I must second the question of whether it is documented or not. – rcollyer Aug 24 '11 at 15:51
  • `Method` isn't documented as an option for either `Graphics` or `BarChart` in the version 8 documentation - time to add to my [http://stackoverflow.com/questions/7087149/how-can-one-find-undocumented-options-or-option-values-in-mathematica][question]. – Verbeia Aug 24 '11 at 21:10
  • @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. – Brett Champion Aug 24 '11 at 21:17
  • 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. – Verbeia Aug 24 '11 at 21:21
  • @500 see [here](http://meta.stackexchange.com/q/99261) for a possible explanation of the disappearing @-username. Personally, I preferred things as they were. – 681234 Sep 10 '11 at 18:33
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

Verbeia
  • 4,400
  • 2
  • 23
  • 44