admin管理员组

文章数量:1297125

Hello all I am working in JavaScript and want to generate colors for my graph.And I want a new color for every line and also the color should be light in shade.

I have read about question of color generation in java script

Random color generator in JavaScript

As I want new color for my line so random number generation will not work in my case Also the color should be light

I have read about the colors RGB values but I didn't find them following any pattern as how to choose light color

So any one can please guide me as is there a way to generate colors in sequence (avoid random) and choose only light color or any other function to make dark color lighter

Thanks

.htm

Hello all I am working in JavaScript and want to generate colors for my graph.And I want a new color for every line and also the color should be light in shade.

I have read about question of color generation in java script

Random color generator in JavaScript

As I want new color for my line so random number generation will not work in my case Also the color should be light

I have read about the colors RGB values but I didn't find them following any pattern as how to choose light color

So any one can please guide me as is there a way to generate colors in sequence (avoid random) and choose only light color or any other function to make dark color lighter

Thanks

http://cloford./resources/colours/500col.htm

Share Improve this question edited May 23, 2017 at 12:01 CommunityBot 11 silver badge asked Jun 27, 2012 at 11:20 A_userA_user 2,1576 gold badges26 silver badges33 bronze badges 1
  • 3 You should use HSL color (google for it) in order to be able to define easily light or dark colors. It's available in HTML5. – Denys Séguret Commented Jun 27, 2012 at 11:23
Add a ment  | 

1 Answer 1

Reset to default 10

You can try this way:

var new_light_color = 'rgb(' + (Math.floor((256-229)*Math.random()) + 230) + ',' + 
                                    (Math.floor((256-229)*Math.random()) + 230) + ',' + 
                                    (Math.floor((256-229)*Math.random()) + 230) + ')';

This way you generate colors that have red, green and blue in the range 230 - 256, which is a light color. You can go lower by changing the numbers, for darker colors.

本文标签: How to generate light colour shades in javascriptStack Overflow