This sounds like you have a bad charge port. It’s possible it’s the battery but most likely, it’s the charge port. As with any electrical component on a phone, they can just fail. It’s also possible that at some point in time, there has been physical damage done to the charging port. Does the charge cable feel snug in the port? If it feels loose there could be something in the charge port that is causing you to have a poor connection. You can try and clean out the charge port with a toothbrush or a small pair of tweezers. Just be careful when you do this. If you have the ability, I would also try a new battery and see if that makes a difference. Before you go though the hassle however, have you tried a different cable with a different power brick?