I am trying to use the EventHandler and have managed to make the text change color upon clicking it, but cannot seem to make each piece of the pie chart change color as I click it. For the text I used this:

f[text_] := DynamicModule[{col = Red}, 
  EventHandler[Style[text, FontColor ->  Dynamic[col]], 
               {"MouseClicked" :> (col = col /. {Red-> Green, Green-> Blue, 
                                   Blue-> Red})}]]

When I apply this function f in the pie chart as follows:

   Labeled[.5, Style[f["A"], Bold]],
   Labeled[.5, Style[f["B"], Bold]]
   }, {
   Labeled[Style[.5, White], Style[f["C"], Bold]]

it works.

How can I make the pieces of the pie change color upon clicking them?

  • $\begingroup$ Avoid using uppercase one-letter symbols as many of them (E, I, ...) have built-in meaning. Better stick to longer names or lowercase characters. $\endgroup$ Commented Dec 1, 2013 at 10:07

1 Answer 1


Interestingly, the Dynamic has to wrap the whole chart, it won't work inside the chart sector as e.g. Button[Style[.7, Dynamic@c], ...]:

c = Yellow;
   {Labeled[.5, f@"AAA"], Labeled[.5, f@"BBB"]},
   {Labeled[.3, f@"CCC"], 
    Button[Style[.7, c], 
     c = c /. {Red -> Blue, Blue -> Green, Green -> Yellow, Yellow -> Red}]}

Mathematica graphics


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.