【发布时间】:2017-06-20 13:37:21
【问题描述】:
我正在使用 ng-2 图表,虽然我可以正确显示饼图,但我无法更改不同饼图的颜色。
似乎存在一个错误,即所有饼图都获得了对象中声明的第一种颜色(在本例中为红色)。
我的 component.ts 看起来像:
public pieChartColors:Array<any> = [
{
backgroundColor: 'red',
borderColor: 'rgba(135,206,250,1)',
},
{
backgroundColor: 'yellow',
borderColor: 'rgba(106,90,205,1)',
},
{
backgroundColor: 'rgba(148,159,177,0.2)',
borderColor: 'rgba(148,159,177,1)',
}
];
// Pie
public pieChartLabels:string[] = ['First Set', 'Sales', 'Mail'];
public pieChartData:number[] = [300, 500, 100];
public pieChartType:string = 'pie';
我的看法:
<canvas
[chartType]="pieChartType"
[colors]="pieChartColors"
[data]="pieChartData"
[labels]="pieChartLabels"
baseChart
></canvas>
【问题讨论】:
标签: javascript angular charts chart.js