Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I change the color for ng2-charts?

I have added ng2-charts to my project and display 2 charts - donut & barchart. both are displayed in gray since I added

    <base-chart class="chart"                 [colors]="chartColors"                 ...     </base-chart>  

to the component.template.html, and

public chartColors:Array<any> =[     {       fillColor:'rgba(225,10,24,0.2)',       strokeColor:'rgba(11,255,20,1)',       pointColor:'rgba(111,200,200,1)',       pointStrokeColor:'#fff',       pointHighlightFill:'#fff',       pointHighlightStroke:'rgba(200,100,10,0.8)'     }, ... (3x) 

to the component.ts.

Are any other package imports necessary to change the color or is the setup wrong?

Chromes html inspector shows the following html output rendered:

ng-reflect-colors="[object Object],[object Object],[object Object]" 
like image 852
edamerau Avatar asked Oct 03 '16 13:10

edamerau


People also ask

How do you modify colors in charts and visuals?

To make changes in the chart color, go to the Format pane and select Data colors. You will see that blue is the default color. There are various options to change the color. You can select from the options, or click on Custom color to select a custom color as shown below.

How do you change colors in Chartjs?

We can use the borderColor property of the dataset to change the color of the line that exists in a line chart. You can assign a color to it in hex or RGBA format.


1 Answers

Also you can do it in this way:

<base-chart class="chart"             [colors]="chartColors"             ... </base-chart> 

and

public chartColors: any[] = [       {          backgroundColor:["#FF7360", "#6FC8CE", "#FAFFF2", "#FFFCC4", "#B9E8E0"]        }]; 
like image 85
Jorge Casariego Avatar answered Oct 05 '22 22:10

Jorge Casariego