Your search did not match any results.

Colorization

This demo shows options that you can use to colorize TreeMap tiles. To see each option, use the drop-down editor below the component.

To colorize the TreeMap tiles, you can use the colorizer object. This object allows you to specify the colorization type:

  • "discrete" (default)
    This colorization algorithm paints each tile within a group in a color from the palette. When there are multiple groups, the way in which groups are colorized depends on the colorizeGroups property setting:

    • If colorizeGroups is set to false (Discrete mode in the demo):
      Each group is painted independently - regardless of the colors used in other groups.

    • If colorizeGroups is set to true (Grouped mode in the demo):
      Each group is painted with a different color from the palette.

  • "gradient"
    If you choose this algorithm, the palette should contain only two colors that the component uses to colorize the smallest and the largest tile, respectively. The other tiles will have a tint of either the first or the second color depending on their size. In order to use the "gradient" algorithm, you need to set the range property to an array of only two values.

  • "range"
    This algorithm is similar to "gradient", but the array assigned to the range property should contain more than two values. This array specifies the ranges between each value. The palette of two colors will generate multiple tints - one for each range.

If you use the "gradient" or "range" colorization algorithm, the color of the tile depends on the value. Normally, the value field supplies this value to the component. However, you can use the colorCodeField property to assign another field to supply the value.

Backend API
@(Html.DevExtreme().TreeMap() .ID("treemap") .DataSource(new[] { new { name = "Monitors", items = new[] { new { name = "DesktopLCD 19", salesAmount = 23420 }, new { name = "DesktopLCD 21", salesAmount = 113900 }, new { name = "DesktopLED 19", salesAmount = 49170 }, new { name = "DesktopLED 21", salesAmount = 81200 } } }, new { name = "Projectors", items = new[] { new { name = "Projector Plus", salesAmount = 99000 }, new { name = "Projector PlusHD", salesAmount = 152250 } } }, new { name = "Televisions", items = new[] { new { name = "SuperLCD 55", salesAmount = 147150 }, new { name = "SuperLCD 42", salesAmount = 103200 }, new { name = "SuperLCD 70", salesAmount = 56000 }, new { name = "SuperLED 42", salesAmount = 159500 }, new { name = "SuperLED 50", salesAmount = 233600 }, new { name = "SuperPlasma 50", salesAmount = 184800 }, new { name = "SuperPlasma 65", salesAmount = 178500 } } }, new { name = "Video Players", items = new[] { new { name = "HD Video Player", salesAmount = 63690 }, new { name = "SuperHD Video Player", salesAmount = 74000 } } } }) .Title("Sales Amount by Product") .ValueField("salesAmount") .Tooltip(t => t .Enabled(true) .Format(Format.Currency) .CustomizeTooltip(@<text> function (arg) { var data = arg.node.data; return { text: arg.node.isLeaf() ? ("<span class='product'>" + data.name + "</span><br />Sales Amount: " + arg.valueText) : null }; } </text>)) .Colorizer(c => c .Type(TreeMapColorizerType.Range) .Range(new double[] { 0, 50000, 100000, 150000, 200000, 250000 }) .Palette(new[] { "#fbd600", "#78299a" }) .ColorCodeField("salesAmount") .ColorizeGroups(false)) ) <div class="options"> <div class="caption">Options</div> <div class="option"> <span>Colorization Type</span> @(Html.DevExtreme().SelectBox() .DataSource(new object[] { new { name = "Discrete", options = new[] { new { type = "discrete", palette = "harmony light", colorizeGroups = false } } }, new { name = "Grouped", options = new[] { new { type = "discrete", palette = "harmony light", colorizeGroups = true } } }, new { name = "Range", options = new[] { new { type = "range", palette = new[] { "#fbd600", "#78299a" }, colorizeGroups = false, range = new[] { 0, 50000, 100000, 150000, 200000, 250000 }, colorCodeField = "salesAmount" } } }, new { name = "Gradient", options = new[] { new { type = "gradient", palette = new[] { "#fbd600", "#78299a" }, colorizeGroups = false, range = new[] { 10000, 250000 }, colorCodeField = "salesAmount" } } } }) .Width(200) .InputAttr("aria-label", "Colorization Type") .DisplayExpr("name") .ValueExpr("name") .Value("Range") .OnValueChanged("selectBox_valueChanged") .ElementAttr("class", "selectbox") ) </div> </div> <script> function selectBox_valueChanged(data) { $("#treemap") .dxTreeMap("instance") .option("colorizer", data.component.option("selectedItem").options[0]); } </script>
using DevExtreme.AspNet.Data; using DevExtreme.AspNet.Mvc; using DevExtreme.MVC.Demos.Models.SampleData; using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Linq; using System.Web.Mvc; namespace DevExtreme.MVC.Demos.Controllers { public class ChartsController : Controller { public ActionResult Colorization() { return View(); } } }
.product { font-weight: 500; } .options { padding: 20px; background-color: rgba(191, 191, 191, 0.15); margin-top: 20px; } .option { margin-top: 10px; } .caption { font-size: 18px; font-weight: 500; } .option > span { margin-right: 10px; } .option > .dx-widget { display: inline-block; vertical-align: middle; }