js写随机一个颜色

绘制图表时,多条数据后台不会规定颜色,so 前台需要自己使用随机色,记录一个小方法:

function randomColor() {
    var arr = ['a', 'b', 'c', 'd', 'e', 'f', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'];
    var chars = '';
    for(var i = 0; i < 6; i ++) {
        chars += arr[Math.round(Math.random() * 100 % 15)]
    }
    return '#' + chars;
}
原文地址:https://www.cnblogs.com/guofan/p/6773758.html