It started life as 'chewing the rag', which was a piece of military slang meaning to whinge/complain rather than just to chat. It first appeared in the 'fat' form in an article in 'Punch' magazine in 1916. The whole idea of the chewing element is in comparison with a dog 'worrying' endlessly at something.