Having this problem is common to the laptop, first can be came from the charger are weak now to perform or the charger pin are in dislocation. The charger pin dislocation means that its need to get the position the charger to make it work. Or a lot kind of issue can be found upon checking of the laptop because one reason too is IC on charger port or charging IC.
Once its define that the problem from a charger. Be careful to buy a replacement of it. Because a lot of fake charger are being out there. It can be seen original but its not and it will result the laptop more damage to the battery or other parts inside the laptop.
Example of image below:
Its mentioned Original but when it use its gives error until the motherboard and battery are damaged.
It still good to use a copy charger but just make it sure that its same configuration of your previous charger and there is no error while using it.
Incase the laptop found that the issue are not from the charger, it a must to bring the laptop to the repair shop to have diagnose and get repaired.