Multiple issues cause this failure. in essence, your device acknowledges the charger, but something is preventing the circuit from charging the battery. Symptoms in likely order are
1) battery: - The battery is not accepting a charge, or draining faster than your charger will pump the life into it. To fix this, replace the battery.
2) Charging Block/Cord: - Your charging apparatus is recognized as a circuit, however, not providing adequate charge to the device. to fix this, replace your Charger. (Block and cable both to be sure) I would never suggest using a charger under 5V/1A output.
3) Charging port.: - The charge port had multiple pins. some for charging, some for data. if one of these pins is failing to connect, it will not charge the device properly, and you can get a slew of different symptoms. the one you are experiencing being one of them. to fix this, replace the charge port. this is a solder job, and i would not suggest doing the repair on your own, unless you have a large amount of experience working with solder.
4) Motherboard: - The circuit that processes the current may be failing on the motherboard. without a developed skillset, it is unrepairable, and replacing the motherboard usually gets more expensive than just buying the phone itself. id look into professionals to do any repairs on the board itself, as micro components are tedious, and painstaking. requiring a microscope, and a concentrated hot air gun.
I hope these helped your diagnosis. Regards.