小编典典

如何更改Angular-Chart.js的颜色

angularjs

我使用Angular-Chart.js(AngularJS
Chart.js版本)创建条形图。图表使用颜色以外的选项。

即使我在文档中进行了设置,它们仍保持灰色。

<div class="graph-display" ng-controller="chartController">
    <canvas class="chart chart-bar"
    data="bilans.data"
    labels="bilans.labels"
    series="bilans.series"
    options="{
        scaleShowHorizontalLines: true,
        scaleShowVerticalLines: false,
        tooltipTemplate: '<%= value %> $',
        responsive: true
    }"
    colours="{
    fillColor: 'rgba(47, 132, 71, 0.8)',
    strokeColor: 'rgba(47, 132, 71, 0.8)',
    highlightFill: 'rgba(47, 132, 71, 0.8)',
    highlightStroke: 'rgba(47, 132, 71, 0.8)'
    }"
    ></canvas>
</div>

实际上,这些选项有效,但颜色无效。难道我做错了什么?


阅读 329

收藏
2020-07-04

共1个答案

小编典典

您应该将colours对象声明为数组

"colours": [{
    fillColor: 'rgba(47, 132, 71, 0.8)',
    strokeColor: 'rgba(47, 132, 71, 0.8)',
    highlightFill: 'rgba(47, 132, 71, 0.8)',
    highlightStroke: 'rgba(47, 132, 71, 0.8)'
}];

plnkr

2020-07-04