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.

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:

PieChart[{{
   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
add comment

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;
Dynamic@PieChart[{
   {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
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.