简体   繁体   English

Angular-charts.js颜色是动态生成的吗?

[英]Angular-charts.js colors dynamically generated?

Do you know if it's possible to give a dynamically generated array of colors to our chart? 您知道是否可以为图表提供动态生成的颜色数组吗?

When i init my colors array with hex colors, it works, but if i give it the return of my "getRandomColor" function, it doesn't work at all. 当我用十六进制颜色初始化我的颜色数组时,它可以工作,但是如果我给它返回“ getRandomColor”函数,则它根本不起作用。

Do you have any idea 你有什么主意吗

$scope.theChart.colours = ["#78CBBC", "#CF207A", "#5DBA1A", "#3AEB06", "#CA5923", "#3C34E0", "#E14FCC"]; // works fine

-- -

$scope.theChart.colours = getcolors(); //doesn't work

function getcolors(array){
var colors = [];
  for (var i = 0; i < 7; i++) {
    colors[i] = getRandomColor();
  }
  return colors;
}

  function getRandomColor() {
    var letters = '0123456789ABCDEF'.split('');
    var color = '#';
    for (var i = 0; i < 6; i++ ) {
        color += letters[Math.floor(Math.random() * 16)];
    }
    return color;
}

Thanks for the help 谢谢您的帮助

您在这里遇到语法错误:

function getcolors(array) { // <- missing {

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM