# Highlight Pie in PieChart

PieChart has the nice functionality of highlighting a single pie when you click on it. It is then sticking out a little. See the following example:

PieChart[{1, 2, 3}]


Now, if I click on the green Pie it starts to stick out.

Is there any way of achieving this programmatically? I browsed through the Options of PieChart but couldn't find anything. I want to automatically create a number of plots with highlighted sections and save them automatically without having to click on them manually each time.

-
There is DynamicModule created which scoped variables are only those responsibile for this. Initial values are set to False, each click changes it to True etc. If you can reconstruct those boxes so that initial value of desired variable is True then it will start as highlighted. – Kuba Feb 12 '14 at 21:24

Something like this perhaps. Thanks to halmir for pointing out that multiple highlighted elements might be useful.

pieHighlight[chart_, n_] := chart /. DynamicModule[init_, body__] :>
(ReplacePart[Hold[init], Thread @ {1, n, 2} -> True] /.
Hold[x_] :> DynamicModule[x, body])


e.g.

PieChart[{1, 2, 3}] ~pieHighlight~ 2


PieChart[{1, 2, 3}] ~pieHighlight~ {1, 2}


-
nice! you could change {1, n, 2} -> True to {1, #, 2} & /@ Flatten[{n}] -> True to allow multiple open pie. i.e, PieChart[{1, 2, 3}]~pieHighlight~{1, 3} – halmir Feb 12 '14 at 22:38
@halmir, good idea to allow multiple highlighted sections, but I prefer Thread@{1, n, 2} – Simon Woods Feb 13 '14 at 10:16