Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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.

share|improve this question
1  
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 at 21:24
add comment

1 Answer

up vote 20 down vote accepted

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

share|improve this answer
1  
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 at 22:38
    
@halmir, good idea to allow multiple highlighted sections, but I prefer Thread@{1, n, 2} –  Simon Woods Feb 13 at 10:16
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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