【问题标题】:Set backgroundColor of bar-char (chart.js)设置条形图的背景颜色(chart.js)
【发布时间】:2020-03-09 11:12:41
【问题描述】:

我在 Angluar 中使用 chart.js 库 (https://www.chartjs.org/docs/latest/charts/bar.html),我想为整个条形图设置 3 种颜色。

当显示超过 3 列时,有没有办法告诉图表应该从头开始应用颜色数组?到目前为止我的代码:

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

输出应该是:红、绿、黄、红、绿、黄、...

【问题讨论】:

    标签: angular colors chart.js


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-01-28
      • 2014-08-28
      • 2023-03-25
      • 1970-01-01
      • 2012-07-15
      • 1970-01-01
      • 2014-06-12
      • 1970-01-01
      相关资源
      最近更新 更多