Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change colours for Angular-Chart.js

I use Angular-Chart.js (the AngularJS Chart.js version) to create a bar chart. The Chart is working with the options except for the colours.

Even if I set them it is indicated in the documentation, they stay grey.

<div class="graph-display" ng-controller="chartController">
    <canvas class="chart chart-bar"
    data="bilans.data"
    labels="bilans.labels"
    series="bilans.series"
    options="{
        scaleShowHorizontalLines: true,
        scaleShowVerticalLines: false,
        tooltipTemplate: '<%= value %> $',
        responsive: true
    }"
    colours="{
    fillColor: 'rgba(47, 132, 71, 0.8)',
    strokeColor: 'rgba(47, 132, 71, 0.8)',
    highlightFill: 'rgba(47, 132, 71, 0.8)',
    highlightStroke: 'rgba(47, 132, 71, 0.8)'
    }"
    ></canvas>
</div>

Actually, the options are working but the colours are not. Am I doing something wrong?

like image 678
Lucien Dubois Avatar asked Feb 21 '15 15:02

Lucien Dubois


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.

Can I use chart JS in angular?

It allows us to create responsive bar charts, pie charts, line plots, donut charts, scatter plots, and other graphs. Simply select where on your page you want a graph to appear, what type of graph you want to plot, and then provide data, labels, and other options to Chart js.


2 Answers

Your should declare colours object as an array

"colours": [{
    fillColor: 'rgba(47, 132, 71, 0.8)',
    strokeColor: 'rgba(47, 132, 71, 0.8)',
    highlightFill: 'rgba(47, 132, 71, 0.8)',
    highlightStroke: 'rgba(47, 132, 71, 0.8)'
}];

Working Plunkr

For more info refer this post / this too.


For newer versions, see eli0tt's answer, as the parameter names have changed.

like image 85
Pankaj Parkar Avatar answered Oct 16 '22 16:10

Pankaj Parkar


I was having the same difficulty. In the docs it says to use "colors" however once I updated my html to:

chart-colours

with an angular array of:

$scope.colours = ['#72C02C', '#3498DB', '#717984', '#F1C40F'];

It worked!

like image 13
Kate S Avatar answered Oct 16 '22 14:10

Kate S