DevExtreme v26.1 is now available.

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

Your search did not match any results.

React Charts - Bar Color Customization

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
import React from 'react'; import { Chart, SeriesTemplate, CommonSeriesSettings, Title, } from 'devextreme-react/chart'; import { dataSource } from './data.ts'; function App() { return ( <Chart id="chart" palette="Soft" dataSource={dataSource}> <CommonSeriesSettings argumentField="age" valueField="number" type="bar" ignoreEmptyPoints={true} /> <SeriesTemplate nameField="age" /> <Title text="Age Breakdown of Facebook Users in the U.S." subtitle="as of January 2024" /> </Chart> ); } export default App;
import React from 'react'; import { Chart, SeriesTemplate, CommonSeriesSettings, Title, } from 'devextreme-react/chart'; import { dataSource } from './data.js'; function App() { return ( <Chart id="chart" palette="Soft" dataSource={dataSource} > <CommonSeriesSettings argumentField="age" valueField="number" type="bar" ignoreEmptyPoints={true} /> <SeriesTemplate nameField="age" /> <Title text="Age Breakdown of Facebook Users in the U.S." subtitle="as of January 2024" /> </Chart> ); } export default App;
import React from 'react'; import ReactDOM from 'react-dom'; import App from './App.tsx'; ReactDOM.render( <App />, document.getElementById('app'), );
export 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 }, ];
import React from 'react'; import ReactDOM from 'react-dom'; import App from './App.js'; ReactDOM.render(<App />, document.getElementById('app'));
export 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 }, ];
<!DOCTYPE html> <html 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" /> <link rel="stylesheet" type="text/css" href="https://cdn3.devexpress.com/jslib/26.1.5/css/dx.light.css" /> <link rel="stylesheet" type="text/css" href="./bundle.css" /> </head> <body class="dx-viewport"> <div class="demo-container"> <div id="app"></div> </div> <script src="bundles/vendor/react.vendor.js"></script> <script src="./bundle.js"></script> </body> </html>
#chart { height: 440px; }