DevExtreme v24.1 is now available.

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

Your search did not match any results.

Custom Bar Width

This demo illustrates how to use the barPadding property to customize bar width.

Backend API
$(() => { $('#chart').dxChart({ palette: 'soft', dataSource, commonSeriesSettings: { barPadding: 0.5, argumentField: 'state', type: 'bar', }, series: [ { valueField: 'year1970', name: '1970' }, { valueField: 'year1980', name: '1980' }, { valueField: 'year1990', name: '1990' }, { valueField: 'year2000', name: '2000' }, { valueField: 'year2008', name: '2008' }, { valueField: 'year2009', name: '2009' }, ], legend: { verticalAlignment: 'bottom', horizontalAlignment: 'center', }, export: { enabled: true, }, title: { text: 'Oil Production', subtitle: { text: '(in millions tonnes)', }, }, }); });
<!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 = [{ state: 'Saudi Arabia', year1970: 186.7, year1980: 480.4, year1990: 319.6, year2000: 465, year2008: 549.7, year2009: 428.4, }, { state: 'USA', year1970: 557.8, year1980: 423.2, year1990: 340.1, year2000: 282.9, year2008: 280, year2009: 298.9, }, { state: 'China', year1970: 32.7, year1980: 87.7, year1990: 165.1, year2000: 126.6, year2008: 191.3, year2009: 181.1, }, { state: 'Canada', year1970: 87.5, year1980: 78.1, year1990: 69.3, year2000: 145.7, year2008: 148.5, year2009: 182.2, }, { state: 'Mexico', year1970: 24.7, year1980: 109.2, year1990: 145.3, year2000: 148.3, year2008: 132.1, year2009: 121.6, }];

Bind to Data

In this demo, the data source array consists of objects with the same field structure. Assign the state field to the argumentField property of the commonSeriesSettings object to specify the common argument for the series. Then, define the series array of objects. In each object, specify the valueField property.

Specify Common Series Settings

To configure settings for all series in the chart, use the commonSeriesSettings object. Specify the barPadding property to control the padding and the width of all bars in a series.

Customize Chart Legend

Use the verticalAlignment and horizontalAlignment properties of the legend object to specify the legend layout.

Export Chart

To allow users to export your bar chart into a PNG, JPEG, PDF, or SVG file, or print the chart, set the export.enabled property to true. Since the export functionality is enabled in this demo, you can click the hamburger button in the chart to invoke a drop-down menu with export and print commands.