There are 3 possible causes of this problem, and each phone is going to be different. The underlying cause is that the phone starts charging, stops charging, then starts charging again.
If the cable is intermittent, or one of the pins at either end is connected badly, this would happen. If the charging port on the phone, or the charging circuit in the phone has a problem it would happen. And if the charger has a problem (once it starts charging the phone, the voltage drops from 5.2 volts to something less than needed for the phone to charge) it would happen.
About the only way to figure out which it is, unless you're a good electronics diagnostician, is to bring the phone, cable and charger to a Device Support Center and ask them to replace whichever part is causing the problem.
Be prepared to wait about an hour or two (maybe even more) once they get to you - they'll have to put the phone on charge, then wait for the problem to occur. Then try it with a different cable. Then with a different charger. It takes time. And your phone isn't the only one they're working on - they'll usually be working on a few at the same time.
Also be prepared to restore all your apps and data to a new phone. If the problem is in the phone, they'll probably just replace it with a working one.