4
$\begingroup$

I'm not looking for something super fancy, but just getting BarChart to show X value and Y value seems to be challenging to get. Here's a toy example.

data = {{"Data 1", -10.}, {"Data 2", 3.}, {"Data 3", -2.0}, { "Data 4", 4.0}}.

BarChart[Tooltip[data]] gives this:

BarChart

How do I modify Tootip to show {Data 2, 3.0} instead of just 3.0?

Thanks for you help!

gani-

$\endgroup$
1
  • $\begingroup$ Also, how do I add a line across y=0? $\endgroup$ Commented Dec 26, 2019 at 22:05

1 Answer 1

8
$\begingroup$
BarChart[Tooltip[#2, {##}] & @@@ data, Axes -> True]

enter image description here

You can also use

BarChart[Tooltip[Last @ #, #] & /@ data, Axes -> True]

same picture

Alternatively, you can set the option value for the option ChartLabels to Placed[data, Tooltip]:

BarChart[data[[All, 2]], Axes -> True, ChartLabels -> Placed[data, Tooltip]]

same picture

$\endgroup$
2
  • $\begingroup$ Thank you! That is an elegant solution.. $\endgroup$ Commented Dec 26, 2019 at 23:37
  • $\begingroup$ @Gani, you're welcome. And welcome to mma.se. $\endgroup$
    – kglr
    Commented Dec 26, 2019 at 23:39

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.