Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
Avoid using uppercase one-letter symbols as many of them (E, I, ...) have built-in meaning. Better stick to longer names or lowercase characters. – István Zachar Dec 1 '13 at 10:07

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

share|improve this answer

Your Answer


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.