score:48
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)'
}];
For more info refer this post / this too.
For newer versions, see eli0tt's answer, as the parameter names have changed.
score:0
With the latest version $scope.colors does not seem to work. You need to use chart-dataset-override="colors"
DEMO
angular.module("app", ["chart.js"]).controller("DoughnutCtrl", function ($scope) {
$scope.results = {'1': 0, '2': 0, '3': 0, '4': 0, '5': 0, '6': 0, '7': 0, '8': 0, '9': 0, '10': 0};
$scope.labels = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10'];
$scope.data = [
[1, 3, 5, 8, 9, 10, 11, 12, 33, 5]
];
$scope.colors = [{
fillColor: 'rgba(59, 89, 152,0.2)',
strokeColor: 'rgba(59, 89, 152,1)',
pointColor: 'rgba(59, 89, 152,1)',
pointStrokeColor: '#fff',
pointHighlightFill: '#fff',
pointHighlightStroke: 'rgba(59, 89, 152,0.8)'
}];
});
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Multi Slot Transclude</title>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.5.0-rc.0/angular.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.3.0/Chart.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular-chart.js/1.0.3/angular-chart.min.js"></script>
</head>
<body ng-app="app" ng-controller="DoughnutCtrl">
<canvas
class="chart chart-bar"
chart-data="data"
chart-labels="labels"
chart-dataset-override="colors">
</canvas>
</body>
</html>
score:2
You wanted to say: "colours"
$scope.colours = ['#FD1F5E','#1EF9A1','#7FFD1F','#68F000'];
Also we can see the other attributes That we can change , like : legend , series, hover . Next to each chart you can see an option called "settings ", that's all what you can change.
score:6
As at 2017 I got angular-charts to work with the following code.
that the names of the elements are changed. Taken from the angular-chart source code.
also that as soon as you run out of colours angular-chart will generate them for you. This includes an opacity of 0.2 for background colours.
If you specify #hex colours opacity will be added.
Colour specification via global.
app.config(['ChartJsProvider', function (ChartJsProvider) {
// Using ChartJsProvider.setOptions('bar', { didn't seem to work for me.
// Nor did $scope.chartColors. Although I only tried that in the controller.
Chart.defaults.global.colors = [
{
backgroundColor: 'rgba(78, 180, 189, 1)',
pointBackgroundColor: 'rgba(78, 180, 189, 1)',
pointHoverBackgroundColor: 'rgba(151,187,205,1)',
borderColor: 'rgba(0,0,0,0',
pointBorderColor: '#fff',
pointHoverBorderColor: 'rgba(151,187,205,1)'
}, {
backgroundColor: 'rgba(229, 229, 229, 1)',
pointBackgroundColor: 'rgba(229, 229, 229, 1)',
pointHoverBackgroundColor: 'rgba(151,187,205,1)',
borderColor: 'rgba(0,0,0,0',
pointBorderColor: '#fff',
pointHoverBorderColor: 'rgba(151,187,205,1)'
}
...
In the source code the colour picking code is currently. Colours set via Chart.js options are reset here (I didn't get this to work).
Pick colours as per angular-chart.js source code:
var colors = angular.copy(scope.chartColors ||
ChartJs.getOptions(type).chartColors ||
Chart.defaults.global.colors
Yes, if you don't specify an object, opacity is set for you. From angular-chart.js:
function convertColor (color) {
if (typeof color === 'object' && color !== null) return color;
if (typeof color === 'string' && color[0] === '#') return getColor(hexToRgb(color.substr(1)));
return getRandomColor();
}
...
function getColor (color) {
return {
backgroundColor: rgba(color, 0.2),
pointBackgroundColor: rgba(color, 1),
pointHoverBackgroundColor: rgba(color, 0.8),
borderColor: rgba(color, 1),
pointBorderColor: '#fff',
pointHoverBorderColor: rgba(color, 1)
};
}
score:7
As @pankajparkar said. Just adding that you can also pass html colours and angular-chart.js will define the colour objects properly in rgba with the proper nuances e.g. $scope.colors = ['#FD1F5E','#1EF9A1','#7FFD1F','#68F000'];
score:7
It seems that naming changed again. I'm using angular-chart.js 1.0.3 and color management for bar charts works like this :
colors:[{
backgroundColor:"#F00",
hoverBackgroundColor:"#FF0",
borderColor:"#0F0",
hoverBorderColor:"#00F"
}];
In the canvas tag, the name of the attribute is chart-colors
score:13
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!
Source: stackoverflow.com
Related Query
- How to change colours for Angular-Chart.js
- Chart js. How to change font styles for "labels" array?
- How to change the position of the tooltip for the Bar type chart in Chart.Js
- How to change label color of ng2 chart in angular
- How can labels/legends be added for all chart types in chart.js (chartjs.org)?
- Chart Js Change Label orientation on x-Axis for Line Charts
- Chart.js how to show cursor pointer for labels & legends in line chart
- How to change tooltip on Angular Chart.js
- How to add second Y-axis for Bar and Line chart in Chart.js?
- Problem for display a chart with Chart.js and Angular
- How do I change the 'months' language displayed on the date axis in Chart JS?
- How to hide the y axis and x axis line and label in my bar chart for chart.js
- Angular 2 chart - change point radius
- How to use 'time' (data from database, data type: timestamp ) for plotting graph in Chart JS
- How do I obtain a Chart instance for Chart.js
- how to change Y axis value dynamically based on user input in Chartjs for Line chart?
- Ng2-charts / chart.js - how to refresh/update chart - angular 4
- Change labels colors for radar chart js
- how to set chart.js grid color for line chart
- PrimeNg bar chart how to show a label for the y-axis
- How to change grid line width for one specific line
- How to update data Chart in async way in Angular Chart.js?
- Angular 8 & ChartJs change color in pie chart
- How to set single color on each bar in angular chart js
- How to change Chart.js horizontal bar chart Width?
- How to change z-index of chart js tooltip?
- Angular chart how to show the legend data value by default along with legend name
- Is it possible to change pointStyle for elements of a ChartJS bubble chart per dataset?
- How to add label in chart.js for polar chart area
- How to show percentage (%) using chartjs-plugin-labels ( Pie chart ) in angular 2/8
More Query from same tag
- Chartjs with zoom plugin zooms too much with wheel just with single turn
- Chart.js - Black bar colors in mobile devices
- Using data in HTML to display ChartJS Doughnut chart
- chart.js cuts off canvas - but padding makes doughnut very small
- create legend from colors saved in const
- Charts Area JS v2: How to set units?
- How i can i reduce the borderwidth of a chartjs dougnut chart
- Loading or Activating ChartJS on Load
- How do I refresh data from json-file with charts.js?
- Chart.JS using Angular.JS on JSFiddle
- How to start the line graph from the left Y axis in a line/bar mixed chart (Chart.js)?
- Angular 4: Different color for bar in bar chart dynamically using ChartJS
- Chart.js data/label scale
- How to access specific data values from tooltip - Chart.js
- Vertical Bar Chart not displaying Correctly
- I am getting TS2339: Property 'chart' does not exist on type 'Window'?
- Popup windows for histogram with AngularJS
- How to make bars dashed in chart js?
- Query result into array in Laravel 6
- How can I create a time series line graph in chart.js?
- Hide chart labels
- How to have custom colors in ng2-charts and chart.js according to data?
- how to display chart data as html table chartjs
- Providing server side data for Chart.js charts
- Chartjs inner separation
- Color by point in ChartJS.Blazor
- ChartJS x axis title not visible when axis position is centered
- Chart.js configuration
- Chart.js not displaying in box
- Limit chart.js X axis ticks