13
$\begingroup$

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.

$\endgroup$

3 Answers 3

11
$\begingroup$

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"] &]]
$\endgroup$
1
  • $\begingroup$ Thank you. The third argument of Placed[ ] helps a lot. $\endgroup$
    – nanjun
    Commented Jan 25, 2017 at 18:53
9
$\begingroup$

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

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

bar chart example

$\endgroup$
2
$\begingroup$

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.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.