The color scheme is the biggest problem of the graphs presentation.
I'm not a coder, but choosing a color in a HSL model (hue, saturation, lightness/luminance) could solve your problem.
For X different colors, divide the Hue scale by X to get the same difference in hue for each color.
I you have more than, say 8 colors, you can get 6 new by selecting a new value for Lightness. And you can again multiply those colors by varying the Saturation.
That way, you will avoid getting too similar colors.