13

Just wondering if anyone knows the proper Syntax to change the Text properties in the BarChart's ChartLegend. I cannot seem to figure out how to get Style[] to apply. Here is an example:

BarChart[{1, 2, 3}, ChartStyle -> "Pastel", 
 ChartLegends -> Placed[{"John", "Mary", "Bob"}, Bottom]]

BarChart[{1, 2, 3}, ChartStyle -> "Pastel", 
 ChartLegends -> Placed[Style[{"John", "Mary", "Bob"},
  FontFamily->"Courier"], Bottom]]

Any help would be greatly appreciated.

t.

Eli Lansey
  • 7,499
  • 3
  • 36
  • 73
T-Diddy
  • 131
  • 3

3 Answers3

11

Actually you can do it without using Map[] as Placed[] takes a third optional argument for cases like this:

BarChart[{1, 2, 3}, ChartStyle -> "Pastel", 
 ChartLegends -> 
  Placed[{"John", "Mary", "Bob"}, Bottom, Style[#, FontFamily -> "Courier"] &]]
Gustavo Delfino
  • 8,348
  • 1
  • 28
  • 58
9

Map[] (i.e., /@) does the trick:

BarChart[{1, 2, 3}, ChartStyle -> "Pastel", 
 ChartLegends -> 
  Placed[Style[#, FontFamily -> "Courier"] & /@ {"John", "Mary", "Bob"}, Bottom]]

bar chart example

J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574
2

One can also do this globally with Legending`LegendContainer:

SetOptions[Legending`GridLegend,
  Legending`LegendContainer -> (Framed @ Append[#, FontFamily -> "Mathematica6"] &)
];

BarChart[{1, 2, 3},
  ChartStyle -> "Pastel", 
  ChartLegends -> Placed[{"John", "Mary", "Bob"}, Bottom]
]

Mathematica graphics

This works because the expression passed to the LegendContainer function has head Style, and Append therefore inserts the given style.

Mr.Wizard
  • 271,378
  • 34
  • 587
  • 1,371