我试图在javascript中随机生成十六进制的颜色.
然而,产生的颜色几乎与彼此无法区分.
有没有办法改善它?
这是我正在使用的代码:
function randomColor(){
var allowed = "ABCDEF0123456789", S = "#";
while(S.length < 7){
S += allowed.charAt(Math.floor((Math.random()*16)+1));
}
return S;
}
Run Code Online (Sandbox Code Playgroud)
我听说过有关HSL和HSV颜色模型的一些内容,但无法在我的代码中使用它.请帮忙.
提前致谢
我一直在使用nvd3很长一段时间.在nvd3中,我们可以选择指定自动图形填充颜色.
chart.barColor()
Run Code Online (Sandbox Code Playgroud)
如何在Chart.js图形中填充随机颜色而不定义数据集中的每种颜色?
我不想使用JavaScript函数生成并从中获取随机颜色.我需要类似于nvd3的东西barColor()
如果有可能的方法,请帮助我.