我正在开发一个有角度的应用程序,并使用ngx-charts,在调试和在线搜索了片刻之后,我找不到如何更改图表上的调色板。
你们知道如何更改ngx图上的调色板吗?
非常感谢您的帮助,谢谢!
答案 0 :(得分:0)
调试一段时间后,我找到了解决方法:
因此,请按以下步骤操作:
第1步:在.ts文件中,添加了一个带有所需颜色的变量
colorScheme = {
domain: ['#5AA454', '#A10A28', '#C7B42C', '#AAAAAA']
};
第2步:在.html文件中,我在[scheme] =“ colorScheme”属性中调用了该变量
<ngx-charts-pie-chart
[results]="chartData.pieChartData.chartPoints"
[legend]="chartData.chartOptions.showLegend"
[explodeSlices]="chartData.chartOptions.explodeSlices"
[labels]="true"
**[scheme]="colorScheme"**
[tooltipDisabled]="!chartData.chartOptions.showToolTip"
[doughnut]="chartData.chartOptions.donut"
aria-hidden="true">
</ngx-charts-pie-chart>
祝你好运!
答案 1 :(得分:0)
使用colorScheme变量可以自定义图表颜色。您可以在文档中找到说明。
https://swimlane.gitbook.io/ngx-charts/examples/pie-charts/pie-chart
图表的自定义颜色。用于覆盖特定值的颜色
src / app.ts
//our root app component
import {Component, NgModule} from '@angular/core';
import {BrowserModule} from '@angular/platform-browser';
import {BrowserAnimationsModule} from '@angular/platform-browser-animations';
import {NgxChartsModule} from '@swimlane/ngx-charts';
import {single, multi} from '../data.ts';
@Component({
selector: 'my-app',
template: `
<ngx-charts-pie-chart
[view]="view"
[scheme]="colorScheme"
[results]="single"
[legend]="showLegend"
[explodeSlices]="explodeSlices"
[labels]="showLabels"
[doughnut]="doughnut"
[gradient]="gradient"
(select)="onSelect($event)">
</ngx-charts-pie-chart>
`
})
export class App {
single: any[];
// chart area size
view: any[] = [700, 400];
// options
showLegend = false;
showLabels = true;
explodeSlices = false;
doughnut = false;
// your color scheme
colorScheme = {
domain: [
'#FF8A80',
'#EA80FC',
'#8C9EFF',
'#80D8FF',
'#A7FFEB',
'#CCFF90',
'#FFFF8D',
'#FF9E80'
]
};
constructor() {
Object.assign(this, {single})
}
// select event
onSelect(event) {
console.log(event);
}
}
@NgModule({
imports: [ BrowserModule, BrowserAnimationsModule, NgxChartsModule ],
declarations: [ App ],
bootstrap: [ App ]
})
export class AppModule {}
data.ts
export var single = [
{
"name": "Apple",
"value": 8940000
},
{
"name": "Banana",
"value": 5000000
},
{
"name": "Ornage",
"value": 7200000
},
{
"name": "Avocado",
"value": 4830200
},
{
"name": "Cherry",
"value": 5520000
},
{
"name": "Coconut",
"value": 1200000
},
{
"name": "Guava",
"value": 2230000
},
{
"name": "Lemon",
"value": 4323000
}
];