Show Chart Category Axis Labels on Multiple Lines
Environment
Product | Progress® Kendo UI® Chart for jQuery |
Operating System | Windows 10 64bit |
Visual Studio Version | Visual Studio 2017 |
Preferred Language | JavaScript |
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>