【发布时间】:2021-03-12 01:42:35
【问题描述】:
我使用 ng2 图表创建了一个条形图。由于标签不可见,条形图具有深色背景。我想自定义标签颜色。我该怎么做??
我的 component.html 代码
<div style="display: block;">
<canvas baseChart [datasets]="barChartData" [labels]="barChartLabels"
[options]="barChartOptions" [plugins]="barChartPlugins"
[colors]="barChartColors"
[legend]="barChartLegend" [chartType]="barChartType">
</canvas>
</div>
我的 component.ts 代码
public barChartOptions:any = {
scaleShowVerticalLines: false,
responsive: true
};
public barChartLabels:string[] = ['male', 'female', 'retired'];
public barChartType:string = 'bar';
public barChartLegend:boolean = true;
public barChartColors:Array<any> = [
{
backgroundColor: '#D4526E',
borderColor: 'rgba(105,159,177,1)',
pointBackgroundColor: 'rgba(105,159,177,1)',
pointBorderColor: '#fafafa',
pointHoverBackgroundColor: '#fafafa',
pointHoverBorderColor: 'rgba(105,159,177)'
},
{
backgroundColor: '#008FFB',
borderColor: 'rgba(77,20,96,1)',
pointBackgroundColor: 'rgba(77,20,96,1)',
pointBorderColor: '#fff',
pointHoverBackgroundColor: '#fff',
pointHoverBorderColor: 'rgba(77,20,96,1)'
},
{
backgroundColor: '#E2C044',
borderColor: 'rgba(77,20,96,1)',
pointBackgroundColor: 'rgba(77,20,96,1)',
pointBorderColor: '#fff',
pointHoverBackgroundColor: '#fff',
pointHoverBorderColor: 'rgba(77,20,96,1)'
}
];
public barChartData:any[] = [
{data: [10,40,65,74,22], label: 'Govt_Jobs'},
{data: [20,46,27,67,89], label: 'Private'},
{data: [38,8,61,26,77], label: 'daily_wage'},
];
【问题讨论】:
-
你能创建一个有问题的 stackblitz 项目吗?
-
这个有办法改变标签字体颜色和颜色stackoverflow.com/questions/52596932/…
标签: angular chart.js ng2-charts