html
<div style="display: block;">
<canvas
baseChart
[data]="pieChartData"
[labels]="pieChartLabels"
[chartType]="pieChartType"
[options]="pieChartOptions"
[plugins]="pieChartPlugins"
[legend]="pieChartLegend"
[colors]="randomColorGenerater()"
>
</canvas>
</div>
ts
public pieChartOptions: ChartOptions = {
responsive: true
};
public pieChart = false;
public pieChartLabels: string[] = [];
public pieChartData: SingleDataSet = [300, 500, 100];
public pieChartType: ChartType = 'pie';
public pieChartLegend = true;
public pieChartPlugins = [];
public pieChartColors = [
{
backgroundColor: [
'rgba(255,0,0,0.3)',
'rgba(0,255,0,0.3)',
'rgba(0,0,255,0.3)'
]
}
];
使用上述代码,我可以显示饼图,但仅使用我在Piechartcolors中给出的颜色,我需要帮助,以便根据将显示的动态数据显示随机颜色。谢谢