Well if it is working fine on battery, just not on the charger cord, then I would say either the charger cord is damaged, or the port where it plugs in is.
I would suggest you try using a different charger cord and see if it works, or if you have the same problem. If the problem goes away, well then you know it was the cord. If the problem persists, then you need to look at the port. Which, if like most laptops, is attached to the motherboard, you may wind up needing the whole motherboard replaced.