Some testing I did (the first 20 seconds are pretty much all there is to see)
here's how it went:
-the first yinyang got me to level 2
-on the second I used the level 2 while being hit, which negated the charge back to level 2
-later I use another level 2 on my last hit, losing the full charge, as expected.
Apparently, when hit, you get the charge after the whole hit animation ends (when you can move again). However, if you use a spell during the animation, the charge you get from what the spell wave clears seems to overwrite the charge you get from being hit, which means you don't get full charge on your last hit. This also applies to charge from normal hits as well, but since losing those isn't nearly as crippling as losing the last hit's, it's pretty much unnoticeable.
From the looks of it, it is clearly a glitch. It seems better to hold your charge on your last hit, even if you end up using a level 3 spell, since that at least leaves you with 2 charges left and whatever you gain from using the spell.