ng2-charts:设置颜色不起作用
ng2-charts: Setting colors not working
我的图表定义为:
<canvas #chart baseChart
[data]="_chartData"
[labels]="_chartLabels"
[chartType]="_chartType"
[colors]="_backgroundColors">
</canvas>
我将颜色指定为:
private _backgroundColors:string[] = ["#345657", "#112288", "#adf444"];
除颜色外一切正常。如果我传入这个数组,所有颜色都显示为相同的颜色,浅灰色。任何人都知道可能出了什么问题吗?
应该是这样的:
[
{
backgroundColor:"#ffa954",
},
{
borderColor:"#589b00",
}
]
其中每个对象代表您的 dataSets
数组中的相应对象
可以找到解决方案here。目前没有记录。
需要这样:
[{backgroundColor: ["#e84351", "#434a54", "#3ebf9b", "#4d86dc", "#f3af37"]}]
我同意上面的回答,如果有人需要,我想提供详细信息。
我的例子在 PIE 图表中,它也适用于其他人。
第 1 步:
在您的 component.ts 文件中添加以下内容
public pieChartColors: Array < any > = [{
backgroundColor: ['#fc5858', '#19d863', '#fdf57d'],
borderColor: ['rgba(252, 235, 89, 0.2)', 'rgba(77, 152, 202, 0.2)', 'rgba(241, 107, 119, 0.2)']
}];
第 2 步:
您的 component.html 应该如下所示:
<canvas baseChart
[data]="pieChartData"
[labels]="pieChartLabels"
[chartType]="pieChartType"
[options]="pieChartOptions"
[plugins]="pieChartPlugins"
[legend]="pieChartLegend"
[colors]="pieChartColors"
(chartHover)="chartHovered($event)"
(chartClick)="chartClicked($event)"
>
</canvas>
我的图表定义为:
<canvas #chart baseChart
[data]="_chartData"
[labels]="_chartLabels"
[chartType]="_chartType"
[colors]="_backgroundColors">
</canvas>
我将颜色指定为:
private _backgroundColors:string[] = ["#345657", "#112288", "#adf444"];
除颜色外一切正常。如果我传入这个数组,所有颜色都显示为相同的颜色,浅灰色。任何人都知道可能出了什么问题吗?
应该是这样的:
[
{
backgroundColor:"#ffa954",
},
{
borderColor:"#589b00",
}
]
其中每个对象代表您的 dataSets
数组中的相应对象
可以找到解决方案here。目前没有记录。
需要这样:
[{backgroundColor: ["#e84351", "#434a54", "#3ebf9b", "#4d86dc", "#f3af37"]}]
我同意上面的回答,如果有人需要,我想提供详细信息。 我的例子在 PIE 图表中,它也适用于其他人。
第 1 步:
在您的 component.ts 文件中添加以下内容
public pieChartColors: Array < any > = [{
backgroundColor: ['#fc5858', '#19d863', '#fdf57d'],
borderColor: ['rgba(252, 235, 89, 0.2)', 'rgba(77, 152, 202, 0.2)', 'rgba(241, 107, 119, 0.2)']
}];
第 2 步:
您的 component.html 应该如下所示:
<canvas baseChart
[data]="pieChartData"
[labels]="pieChartLabels"
[chartType]="pieChartType"
[options]="pieChartOptions"
[plugins]="pieChartPlugins"
[legend]="pieChartLegend"
[colors]="pieChartColors"
(chartHover)="chartHovered($event)"
(chartClick)="chartClicked($event)"
>
</canvas>