Your search did not match any results.

Charts - Side-by-Side Stacked Bar

This demo shows the side-by-side stacked bar series that allows you to visualize data as bars stacked in different groups. This series type is useful when you compare values of an individual series with the total values of groups.

www.wikipedia.org
Backend API
@(Html.DevExtreme().Chart() .ID("chart") .CommonSeriesSettings(s => s .ArgumentField("State") .Type(SeriesType.StackedBar) ) .Series(s => { s.Add().ValueField("Maleyoung").Name("Male: 0-14").Stack("Male"); s.Add().ValueField("Malemiddle").Name("Male: 15-64").Stack("Male"); s.Add().ValueField("Maleolder").Name("Male: 65 and older").Stack("Male"); s.Add().ValueField("Femaleyoung").Name("Female: 0-14").Stack("Female"); s.Add().ValueField("Femalemiddle").Name("Female: 15-64").Stack("Female"); s.Add().ValueField("Femaleolder").Name("Female: 65 and older").Stack("Female"); }) .Legend(l => l .HorizontalAlignment(HorizontalAlignment.Right) .Position(RelativePosition.Inside) .Border(b => b.Visible(true)) .ColumnCount(2) .CustomizeItems("customizeLegendItems") ) .ValueAxis(a => a .Add().Title(t => t.Text("Populations, millions")) ) .Title("Population: Age Structure") .Export(e => e.Enabled(true)) .Tooltip(t => t.Enabled(true)) .DataSource(new[] { new { State = "USA", Maleyoung = 29.956, Malemiddle = 90.354, Maleolder = 14.472, Femaleyoung = 28.597, Femalemiddle = 91.827, Femaleolder = 20.362 }, new { State = "Brazil", Maleyoung = 25.607, Malemiddle = 55.793, Maleolder = 3.727, Femaleyoung = 24.67, Femalemiddle = 57.598, Femaleolder = 5.462 }, new { State = "Russia", Maleyoung = 13.493, Malemiddle = 48.983, Maleolder = 5.802, Femaleyoung = 12.971, Femalemiddle = 52.14, Femaleolder = 12.61 }, new { State = "Japan", Maleyoung = 9.575, Malemiddle = 43.363, Maleolder = 9.024, Femaleyoung = 9.105, Femalemiddle = 42.98, Femaleolder = 12.501 }, new { State = "Mexico", Maleyoung = 17.306, Malemiddle = 30.223, Maleolder = 1.927, Femaleyoung = 16.632, Femalemiddle = 31.868, Femaleolder = 2.391 }, new { State = "Germany", Maleyoung = 6.679, Malemiddle = 28.638, Maleolder = 5.133, Femaleyoung = 6.333, Femalemiddle = 27.693, Femaleolder = 8.318 }, new { State = "United Kindom", Maleyoung = 5.816, Malemiddle = 19.622, Maleolder = 3.864, Femaleyoung = 5.519, Femalemiddle = 19.228, Femaleolder = 5.459 } }) ) <script> function customizeLegendItems(items) { var sortedItems = []; items.forEach(function (item) { var startIndex = item.series.stack === "Male" ? 0 : 3; sortedItems.splice(startIndex, 0, item); }); return sortedItems; } </script>
using DevExtreme.AspNet.Data; using DevExtreme.AspNet.Mvc; using DevExtreme.NETCore.Demos.Models; using DevExtreme.NETCore.Demos.Models.SampleData; using Microsoft.AspNetCore.Mvc; using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Linq; namespace DevExtreme.NETCore.Demos.Controllers { public class ChartsController : Controller { public ActionResult SideBySideStackedBar() { return View(); } } }
#chart { height: 440px; }

Bind Chart to Data

The side-by-side stacked bar chart contains series with the same argument field. In this demo, the data source array consists of the 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 and use the stack property to group the series in stacks depending on the stack property values.

Customize Side-By-Side Stacked Bar Chart

Customize Chart Legend

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

The customizeLegend function allows you to change the order, text, and visibility of legend items. This demo uses the array.splice method in the customizeItems function to sort the legend items. If you want to customize the legend border, use properties collected in the border object.

To distribute all legend items between multiple columns (in a vertically-oriented legend) or rows (in a horizontally-oriented legend), specify the columnCount or rowCount property, respectively.

Configure Tooltips

To configure tooltips in the chart, use the tooltip object. To enable the tooltips, assign true to the enabled property of this object.

Export Chart

To allow users to export your side-by-side stacked bar chart into a PNG, JPEG, PDF, and 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.