I am using ngx-charts with Angular 12 and I'm getting this error message then I use this:
colorScheme = {
domain: ['#5AA454', '#A10A28', '#C7B42C', '#AAAAAA']
};
The error message is:
Type '{ domain: string[]; }' is not assignable to type 'string | Color'.
How can I fix this?
Use the ngx-charts version 18 or below.
The scheme type [scheme]="colorScheme", is asking for a string but the type you are providing is an object.
The latest version 19 or above as scheme type is of string | color.
ngx-charts version 19 or above accepts only types string or Color (from here), and to expand on another answer:
"cool", "natural", "vivid", etc from the preset color schemes in this file.import { Color, ScaleType } from '@swimlane/ngx-charts';
export class foo {
colorScheme: Color = {
name: 'myScheme',
selectable: true,
group: ScaleType.Ordinal,
domain: ['#f00', '#0f0', '#0ff'],
};
}
<ngx-charts-area-chart
...
[scheme]="colorScheme"
></ngx-charts-area-chart>