try a different ROM, xfinity was pulled by the dev a couple days ago due to issues (not knocking that ROM at all).
I would recommend my ROM (n00b) as a good starting point to rule out it being software, I have no one reporting this issue. Test the phone after a fresh install before adding any apps etc for a few hours. If the issue goes away then slowly add apps and retest to rule out apps. If you no longer have an issue, my guess would be the kernel that was included in the ROM, I don't know what version of xfinity you had, but if it was before the last beta you had an experimental Kernel that still had some bugs. If it persists, it could be a hardware issue or charger issue (you said it only happens while charging, right?) have you tried charging from a usb port on your computer? It could be something simple like the charger itself, it could also be the battery. To rule out the battery, turn the phone on, connect it to the charger and then remove the battery and see if it still happens (the phone should stay on without the battery as long as it's plugged in).
One other thing to try, put the phone in airplane mode and see if it still happens, it could be one specific radio (wifi/signal/gps/bluetooth) that's causing it. Try turning them all off and see if it happens, maybe the phone overheats or something because of charging and using a certain radio at the same time.
I know this is a lot of thoughts, but hopefully you can narrow it down using some of these ideas.