AUTHOR: Veselina Raykova
DATE POSTED: October 03, 2018
As the Legend template of the Chart is called for each legend item, we will add the title as a part to the first item (or before it, to be precise). In order to cancel the default show/hide series functionality of the legend items, we will also need to prevent the click and hover logic of the added element. Below are the main steps we will go through in order to achieve the target result:
You can see the implementation of the above steps below, as well to directly test the result of applying the same code to a Kendo Chart widget here: https://dojo.telerik.com/uKIGiNEx
<
telerik:RadHtmlChart
runat
=
"server"
ID
"RadHtmlChart1"
Width
"800px"
Height
"400px"
>
ClientEvents
OnLegendItemClick
"legendItemClickOrHover"
OnLegendItemHover
/>
Legend
Appearance
Position
"right"
Item
Visual
"legendVisual"
</
PlotArea
..
function
legendVisual(e) {
var
title = e.series.index == 0 ?
"Legend Title Here"
:
" "
;
//there has to be whitespace so it gets rendered
// Define the target dimensions for the legend item
rect =
new
kendo.geometry.Rect([0, 200], [100, 50]);
layout =
kendo.drawing.Layout(rect, {
spacing: 5,
alignItems:
"left"
});
innerRect =
innerLayout =
kendo.drawing.Layout(innerRect, {
orientation:
"vertical"
//Position and style the title in the prefered way
txt =
kendo.drawing.Text(title, [20, -30], {
font:
"18px sans-serif"
//add the legend title to the legend item
innerLayout.append(txt);
// This will give us the default box + text
innerLayout.append(e.createVisual());
layout.append(innerLayout);
return
layout;
}
legendItemClickOrHover(e) {
if
(e.element.nodeName ==
"text"
) {
e.preventDefault();
RadHtmlChart Client-side Events
RadHtmlChart Visual Templates
Kendo UI Drawing API
Resources Buy Try