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

2024-04-07

我使用 Angular-Chart.js(AngularJSChart.js http://www.chartjs.org/版本)来创建条形图。图表正在使用除颜色之外的选项。

即使我设置了它们,它也会显示在文档中 http://jtblin.github.io/angular-chart.js/#bar-chart,它们保持灰色。

<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>

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


你应该声明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)'
}];

工作笨蛋 http://plnkr.co/edit/SYgfQTTEC2XD1OA0ZReV?p=preview

欲了解更多信息,请参阅这个帖子 https://stackoverflow.com/questions/28278178/load-json-to-display-data-using-ng-repeat/28278331#28278331 / this https://stackoverflow.com/questions/28278096/angular-js-loading-data-for-chart/28278459#28278459 too.


对于较新的版本,请参阅埃利奥特的回答 https://stackoverflow.com/a/40282914/59087,因为参数名称已更改。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何更改 Angular-Chart.js 的颜色 的相关文章

随机推荐