DevExtreme v24.2 is now available.

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

Your search did not match any results.

JavaScript/jQuery Charts - Stacked Bar

This demo shows the stacked bar series type that visualizes data as columns stacked over each other. You can use this series type to compare values of an individual series with total values aggregated for each argument.

www.wikipedia.org
Backend API
$(() => { $('#chart').dxChart({ dataSource, commonSeriesSettings: { argumentField: 'state', type: 'stackedBar', }, series: [ { valueField: 'young', name: '0-14' }, { valueField: 'middle', name: '15-64' }, { valueField: 'older', name: '65 and older' }, ], legend: { verticalAlignment: 'bottom', horizontalAlignment: 'center', itemTextPosition: 'top', }, valueAxis: { title: { text: 'millions', }, position: 'right', }, title: 'Male Age Structure', export: { enabled: true, }, tooltip: { enabled: true, location: 'edge', customizeTooltip(arg) { return { text: `${arg.seriesName} years: ${arg.valueText}`, }; }, }, }); });
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml" 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="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></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="https://cdn3.devexpress.com/jslib/24.2.3/css/dx.light.css" /> <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: 'Germany', young: 5.3, middle: 26, older: 8, }, { state: 'Japan', young: 6.45, middle: 30.5, older: 11.22, }, { state: 'Russia', young: 12.56, middle: 45.5, older: 6.5, }, { state: 'USA', young: 32, middle: 87, older: 15, }];

Bind to Data

In this demo, series is bound to data directly. See the Bind Series to Data article for information. The "state" field name is assigned to the argumentField property of the commonSeriesSettings object since the stacked bar chart contains series with the same argument field.

Specify Common Series Settings

To configure settings for all series in the chart, use the commonSeriesSettings object. For example, specify the series type.

Customize Stacked Bar Chart

Use the verticalAlignment and horizontalAlignment properties of the legend object to specify the legend position in the chart. You can specify the text's position relative to the marker in a legend item in the itemTextPosition property.

To configure tooltips in the chart, use the tooltip object. To enable the tooltips, assign true to the enabled property of this object. If you want to customize a specific tooltip, assign a function to the customizeTooltip property. In this demo, the function returns the tooltip's text that shows the series name and point value.