New to Kendo UI for jQueryStart a free 30-day trial

Show Chart Category Axis Labels on Multiple Lines

Environment

ProductProgress® Kendo UI® Chart for jQuery
Operating SystemWindows 10 64bit
Visual Studio VersionVisual Studio 2017
Preferred LanguageJavaScript

Description

How can I display long labels in a Kendo UI Chart and make the content look more compact and better organized?

Solution

It is possible to break the content of the Chart labels into multiple lines.

The following example demonstrates how to insert newline symbols in the Category Axis labels to achieve this behavior.


    <div id="chart"></div>
    <script>
      var data = [{
        value: 1,
        category: "Category Foo"
      },{
        value: 2,
        category: "Category Bar"
      }, {
        value: 3,
        category: "Category Baz"
      }];

      $("#chart").kendoChart({
        dataSource: {
          data: data
        },
        series: [{
          type: "column",
          name: "Series Name",
          field: "value"
        }],
        categoryAxis: {
          field: "category",
          labels: {
            template: labelTemplate
          }
        }
      });

      function labelTemplate(e) {
        return e.value.split(" ").join("\n");
      }
    </script>

See Also