DevExtreme v24.1 is now available.

Explore our newest features/capabilities and share your thoughts with us.

Your search did not match any results.

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
$(() => { $('#chart').dxChart({ 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="" lang="en"> <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=5.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="js/dx.all.js"></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"> <div id="chart"></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 }, ];