We use this expression to show a complete opposite in personality between two people.

Example:

Joan: Have you met Linda and Brian yet?

Mary: Yes, I have. I thought they were a lovely couple.

Joan: Yes, I agree but they are totally different, Linda is a delightful happy young lady and Brian is a bit miserable, just like chalk and cheese, but people do say that opposites are attracted to each other!