Your search did not match any results.
Bar Charts

Color Each Bar Differently


The Chart assigns one color to one series. To color bars differently, create a separate series for each bar.

Assign the age field to the argumentField property of the commonSeriesSettings object to specify a common argument for the series. Then specify the valueField property.

Choose a data field and assign it to the seriesTemplate.nameField property. Each value from this data field generates a separate series.

To learn more about this type of data binding, refer to the following demo: Dynamic Series from the DataSource.

Backend API
Copy to CodePen
const DemoApp = angular.module('DemoApp', ['dx']); DemoApp.controller('DemoController', ($scope) => { $scope.chartOptions = { dataSource, palette: 'soft', title: { text: 'Age Breakdown of Facebook Users in the U.S.', subtitle: 'as of January 2017', }, commonSeriesSettings: { type: 'bar', valueField: 'number', argumentField: 'age', ignoreEmptyPoints: true, }, seriesTemplate: { nameField: 'age', }, }; });
<!DOCTYPE html> <html xmlns=""> <head> <title>DevExtreme Demo</title> <meta http-equiv="X-UA-Compatible" content="IE=edge" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0" /> <script src=""></script> <script>window.jQuery || document.write(decodeURIComponent('%3Cscript src="js/jquery.min.js"%3E%3C/script%3E'))</script> <link rel="stylesheet" type="text/css" href="" /> <script src=""></script> <script>window.angular || document.write(decodeURIComponent('%3Cscript src="js/angular.min.js"%3E%3C/script%3E'))</script> <script src=""></script> <script src="data.js"></script> <link rel="stylesheet" type="text/css" href="styles.css" /> <script src="index.js"></script> </head> <body class="dx-viewport"> <div class="demo-container" ng-app="DemoApp" ng-controller="DemoController"> <div id="chart" dx-chart="chartOptions"></div> </div> </body> </html>
#chart { height: 440px; }
const dataSource = [ { age: '13-17', number: 6869661 }, { age: '18-24', number: 40277957 }, { age: '25-34', number: 53481235 }, { age: '35-44', number: 40890002 }, { age: '45-54', number: 31916371 }, { age: '55-64', number: 13725406 }, { age: '65+', number: 16732183 }, ];