TransWikia.com

BarChart with two ChartLabels

Mathematica Asked by JavaCake on February 25, 2021

I am creating a BarChart, where i wish to have the actual value on the top of each bar and the label of the bar on the bottom. Basically i have created the BarChart with the label in the bottom, but i cannot figure out how to add the value on the top of each bar.

values = {150445, 161419, 173986, 202405, 214516, 227004, 
   240700, 256377, 271309, 286944, 307016, 320545};
labels = {2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
    2009, 2010, 2011, 2012};
Show[
 BarChart[values, ChartLabels -> labels, 
  ChartStyle -> "Pastel", AxesLabel -> {"Year", "Diagnosis"}],
 Background -> Transparent,
 BaseStyle -> {12, FontFamily -> "Helvetica"},
 ImageSize -> 600
 ]

Is there a way to view the valueson top of each bar?

2 Answers

 BarChart[Labeled[#, {#, #2}, {Above, Below}] & @@@ Thread[{values, Most@labels}],
   ChartStyle -> "Pastel", 
   AxesLabel -> {"Year", "Diagnosis"}, Background -> Transparent, 
   BaseStyle -> {12, FontFamily -> "Helvetica"}, ImageSize -> 600]

enter image description here

Correct answer by kglr on February 25, 2021

This is a bit hackish, but it is convenient in this case:

BarChart[
 AssociationThread[labels, values],
 ChartLabels -> Automatic,
 LabelingFunction -> Above
]

Answered by Szabolcs on February 25, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP