Angular 设置条形字符(chart.js)的背景色

Angular 设置条形字符(chart.js)的背景色,angular,colors,chart.js,Angular,Colors,Chart.js,我正在使用英语和chart.js库()工作,我想为整个条形图设置3种颜色 当显示超过3列时,是否有方法告诉图表应从一开始就应用颜色数组?到目前为止,我的代码是: colors: ['red','green','yellow'] 输出应该是:红色、绿色、黄色、红色、绿色、黄色,…您可以使用简单的编程逻辑。 colorIndex=columnNumber%3 使用模运算符。其余的你可以思考。希望能有帮助 data: { datasets: [{ barPercentage

我正在使用英语和chart.js库()工作,我想为整个条形图设置3种颜色

当显示超过3列时,是否有方法告诉图表应从一开始就应用颜色数组?到目前为止,我的代码是:

colors: ['red','green','yellow']

输出应该是:红色、绿色、黄色、红色、绿色、黄色,…

您可以使用简单的编程逻辑。
colorIndex=columnNumber%3
使用模运算符。其余的你可以思考。希望能有帮助

data: {
    datasets: [{
        barPercentage: 0.5,
        barThickness: 6,
        maxBarThickness: 8,
        minBarLength: 2,
        data: [10, 20, 30, 40, 50, 60, 70]
        backgroundColor: colors,
    }]
};