Consider this jsfiddle link Here I would like to join the scatter dots with lines of different colors. That is if lines have varying x value then the line should have one color and if x value remains constant then the line joining scatter dots must have different color as shown below. How to do this ?