【发布时间】:2020-09-15 12:15:15
【问题描述】:
我开始使用Angular 中的Chart.js 和ng2-Charts。现在我在做甜甜圈图,想做一个多级图表,但不能改变每个级别的颜色。我选择的颜色只在第一级,其他都没有。
这是我的 doughnut-chart.component.ts:
import { Component } from '@angular/core';
import { ChartType, ChartOptions } from 'chart.js';
import { MultiDataSet, Label, Color } from 'ng2-charts';
@Component({
selector: 'doughnut-chart',
templateUrl: './doughnut-chart.component.html',
styleUrls: ['./doughnut-chart.component.css']
})
export class DoughnutChartComponent {
doughnutChartLabels: Label[] = ['SPD', 'CDU', 'Grüne', "Linke", "FDP", "AFD", "Andere"];
doughnutChartData: MultiDataSet = [
[33, 21, 9, 9, 11, 13, 5 ],
[35, 20, 10, 10, 15, 15, 10 ],
[40, 15, 5, 15, 20, 5, 20 ]
];
public doughnutChartColors: Color[] = [
{
backgroundColor:
[
'red',
'black',
'green',
"purple",
"yellow",
"blue",
"grey"
],
hoverBackgroundColor:
[
"lightgrey",
"grey",
"lightgrey",
"grey",
"lightgrey",
"grey",
"lightgrey",
],
}
];
doughnutChartType: ChartType = 'doughnut';
doughnutChartOption: ChartOptions = {}
}
有人知道该怎么做吗?我在 Internet 上没有找到有关此主题的任何信息。
【问题讨论】:
标签: angular typescript chart.js ng2-charts