How to make the bar be a button?
You can wrap input data with Button
with action CopyToClipboard
:
data = {1, 2, 3};
BarChart[Button[Tooltip[#, "I want tip"], CopyToClipboard@#] & /@ data,
ChartElementFunction -> "GlassRectangle", ChartStyle -> "Pastel"]
Update: You can add tool tips in several ways:
tooltips = {"tooltip1", "tooltip2", "tooltip3"};
- Use
Tooltip
as a wrapper on input data:
BarChart[Button[Tooltip@##, CopyToClipboard[#]] & @@@
Transpose[{{1, 2, 3}, tooltips}],
ChartElementFunction -> "GlassRectangle", ChartStyle -> "Pastel"]
- Use
Placed[tooltips, Tooltip]
as the setting for the optionChartLabels
:
BarChart[Button[#, CopyToClipboard[#]] & /@ data,
ChartElementFunction -> "GlassRectangle", ChartStyle -> "Pastel",
ChartLabels -> Placed[tooltips, Tooltip]]
- Use a custom
ChartElementFunction
and pass the tooltips as metadata:
ceF[cedf_: "GlassRectangle"] := Button[Tooltip[ChartElementData[cedf][##], #3[[1]]],
BarChart[Thread[data -> tooltips], ChartElementFunction -> ceF[],
ChartStyle -> "Pastel", PlotLabel -> (Paste[])]
This is to get a slightly modified version of kglr's comments recorded as an answer. The modification is provide individual tooltips for each bar.
BarChart[
MapThread[
Button[Tooltip[#1, #2], CopyToClipboard@#1] &,
{{1, 2, 3}, {"left", "mid", "right"}}],
ChartElementFunction -> "GlassRectangle", ChartStyle -> "Pastel"]
.1
Also, be aware that if only want the tooltip to show the value of the bar, you don't need to specify Tooltip
; it will be supplied automatically.
BarChart[Button[#, CopyToClipboard@#] & /@ {1, 2, 3},
ChartElementFunction -> "GlassRectangle", ChartStyle -> "Pastel"]