20
$\begingroup$

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}]

enter image description here

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

enter image description here

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.

$\endgroup$
1
  • 1
    $\begingroup$ 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. $\endgroup$
    – Kuba
    Feb 12, 2014 at 21:24

1 Answer 1

20
$\begingroup$

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

enter image description here

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

enter image description here

$\endgroup$
2
  • 1
    $\begingroup$ 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} $\endgroup$
    – halmir
    Feb 12, 2014 at 22:38
  • $\begingroup$ @halmir, good idea to allow multiple highlighted sections, but I prefer Thread@{1, n, 2} $\endgroup$ Feb 13, 2014 at 10:16

Your Answer

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

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