# Implement Color-Coded Ranges in Chart Bars

## Environment

<table>
 <tr>
  <td>Product</td>
  <td>Progress® Kendo UI® Chart for jQuery</td>
 </tr>
 <tr>
  <td>Operating System</td>
  <td>Windows 10 64bit</td>
 </tr>
 <tr>
  <td>Visual Studio Version</td>
  <td>Visual Studio 2017</td>
 </tr>
 <tr>
  <td>Preferred Language</td>
  <td>JavaScript</td>
 </tr>
</table>

## Description

How can I implement color-coded ranges in the bars of the Chart?

## Solution

You can use color ranges for conveying additional information, for example, value composition.

To achieve this behavior, you can normally use the stacked bar series. However, if you need to convey more flexibility, consider the following Chart.

![Kendo UI for jQuery Color ranges in a Kendo UI Chart](https://www.telerik.com/kendo-jquery-ui/documentation/assets/887ae23bf62ec1ee85f6e538b183c419/color-coded-bars.png)

To implement the functionality as shown in the image, define a [`series.visual`](https://www.telerik.com/kendo-jquery-ui/documentation/api/dataviz/ui/chart/configuration/series#seriesvisual) that draws the ranges dynamically. Note that the visual remains in use until the next [`render` event](https://www.telerik.com/kendo-jquery-ui/documentation/api/dataviz/ui/chart/events/render). This allows you to update it asynchronously or in real-time.

The following example demonstrates how to implement color-coded ranges (stripes) in bars when working with Kendo UI Charts.

```dojo
    <div id="chart" />
    <script>
      var WIDTH = 5;
      var draw = kendo.drawing;
      var geom = kendo.geometry;

      $("#chart").kendoChart({
        series: [{
          type: "bar",
          data: [10, 20, 30],
          // https://docs.telerik.com/kendo-ui/api/dataviz/ui/chart/configuration/series#seriesvisual
          visual: function(e) {
            // https://docs.telerik.com/kendo-ui/api/geometry/rect
            var left = e.rect.topLeft();
            var right = e.rect.topRight();
            var bottom = e.rect.bottomLeft();

            // https://docs.telerik.com/kendo-ui/api/drawing/group
            var group = new draw.Group();

            for (var x = left.x; x < right.x; x += WIDTH) {
              var rect = new geom.Rect([x, left.y], [WIDTH, e.rect.height()])

              // https://docs.telerik.com/kendo-ui/api/drawing/path
              var value = Math.random();
              var path = draw.Path.fromRect(rect, {
                fill: {
                  color: value > 0.5 ? "green" : "lightgreen"
                },
                stroke: null,

                // Custom field
                value: value
              });

              group.append(path);
            }

            return group;
          }
        }]
      });
    </script>
```

## See Also

* [Chart JavaScript API Reference](https://www.telerik.com/kendo-jquery-ui/documentation/api/dataviz/ui/chart)
* [Drawing API](https://www.telerik.com/kendo-jquery-ui/documentation/framework/drawing/overview)
* [Aggregate Data in Pie Charts](https://www.telerik.com/kendo-jquery-ui/documentation/knowledge-base/pie-chart-aggregates)
* [Draw on Scatter Plots Surface](https://www.telerik.com/kendo-jquery-ui/documentation/knowledge-base/draw-on-scatter-plots)
* [Expand Clickable Area of Points](https://www.telerik.com/kendo-jquery-ui/documentation/knowledge-base/expand-clickable-area)
