Your search did not match any results.

Bi-Directional Bar Chart

To create a bi-directional bar chart, follow the steps below.

Backend API
@(Html.DevExtreme().Chart() .ID("chart") .Title("Population Pyramid For Norway 2016") .Rotated(true) .BarGroupWidth(18) .CommonSeriesSettings(s => s .ArgumentField("Age") .Type(SeriesType.StackedBar) ) .Series(s => { s.Add() .ValueField("Male") .Name("Male") .Color("#3F7FBF"); s.Add() .ValueField("Female") .Name("Female") .Color("#F87CCC"); }) .Tooltip(t => t .Enabled(true) .CustomizeTooltip(@<text> function (arg) { return { text: Math.abs(arg.valueText) }; } </text>) ) .ValueAxis(a => { a.Add() .Label(l => l.CustomizeText(@<text> function (arg) { return Math.abs(arg.value) + "%"; } </text>)); }) .Legend(l => l .VerticalAlignment(VerticalEdge.Bottom) .HorizontalAlignment(HorizontalAlignment.Center) .Margin(m => m.Left(50)) ) .DataSource(Model) )
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 BiDirectionalBarChart() { return View(SampleData.PopulationPyramidData); } } }
#chart { height: 549px; width: 820px; margin: 0 auto; }
  1. Convert half of the data source values from positive to negative. In this demo, the male percentages are negative, while the female are positive.

  2. Implement a rotated stacked bar chart. Use the commonSeriesSettings object to specify the type and the argumentField property (age in this case). Set the rotated property to true.

  3. Declare two objects in the series array: one for negative values, the other for positive. Specify the color, name, and valueField for each series.

  4. Change the label text of the valueAxis so that the negative values appear as positive. To implement this technique, use the customizeText function.

To further customize your bi-directional bar chart, implement tooltips and change the legend's alignment.