I want to access the index for the following events: seriesClick and seriesHover. I only see how to access the value and category of the particular bar in the documentation here http://docs.kendoui.com/api/dataviz/chart#events-seriesClick but not the data of the original object the item is based on.
4 Answers
You have access to the respective data item in e.dataItem
, for example, so you could do:
var data = e.sender.dataSource.data();
for (var i=0; i < data.length ; i++) {
if (e.dataItem.uid === data[i].uid) {
console.log("index " + i);
}
}
if that is what you mean by "index".
You also have access to the series data in e.series
(but all of that is in the documentation).

- 18,252
- 2
- 45
- 73
The default data series for a Kendo Graph is an array of numeric values. These values do not have a uid, since they are not objects.
Instead of creating an array of numbers in your series object, create an array of objects. Within the series element, create an attribute called 'field' and populate that field with the name of the field in your object that holds the numeric value that you want to chart. This object will have a uid. I am doing this so that I can associate a url with the data point and will move to that page when clicked.
My objects are made in C# and passed in using JSON, but you can make these objects howevery your like.
public class DowntimeAnalysisSeries : DatabagUtility
{
public string name { get; set; }
public string field { get; set; }
public DowntimeAnalysisDatapoint[] data { get; set; }
//public decimal[] data { get; set; }
public string color { get; set; }
}
public class DowntimeAnalysisDatapoint
{
public decimal dataValue { get; set; }
public string url { get; set; }
}
Now you can use the logic described above by Lars Höppner. Once I have put my data into an object, I no longer need to know the index, since Kendo gives it to me.
I attach to the series clicked event by putting the following line into the graph setup:
seriesClick: function (e){rla_summaryBarClicked(e);}
The function that I call is as follows:
function rla_detailBarClicked(e) {
var item = e.dataItem;
var url=item.url;
// do stuff with url here...
}
}
All information that I stuffed into the dataItem is available to me.

- 1,266
- 1
- 14
- 24
-
One thing to note here is for this solution to work, you also need to set the field property: .Field("dataValue") – Flores Dec 27 '14 at 08:16
I didn't find neither member e.series or e.uid in the event structure which is the next:
e: Object
_defaultPrevented: false
category: Tue Jul 05 2011 12:00:00 GMT+0400
element: S.fn.init[1]
isDefaultPrevented: function (){return this._defaultPrevented===!0}
preventDefault: function (){this._defaultPrevented=!0}
sender: vn.extend.init
value: 9.833887
__proto__: Object
But in the same time array item it has:
100: i.extend.o
DateTimeLocal: Sat Jul 02 2011 00:00:00 GMT+0400
DateTimeUTC: "/Date(1309554000000)/"
Value: 0.6488973049506388
_date_DateTimeLocal: Sat Jul 02 2011 00:00:00 GMT+0400
_events: Object
dirty: false
parent: function (){return r}
uid: "e5376556-c50b-4653-8889-5eb4ea7c2c28"
DateTime comparing also gives no result applying this block
var data = e.sender.dataSource.data();
for (var i = 0; i < data.length ; i++) {
var d = data[i].DateTimeLocal;
if (e.category == data[i].DateTimeLocal) {
console.log("index " + i);
}
}

- 51
- 1
- 2
-
you shouldn't use "answer" for this - edit your question and/or comment on answers; in your case, I'd suggest trying to create a demo to illustrate your problem - you can start with this: http://jsfiddle.net/lhoeppner/Z6DsC/2/ – Lars Höppner Dec 16 '13 at 09:50
-
Chart not clikable on the link. Console log is empty and not show array index. – user3058713 Dec 16 '13 at 10:27
-
Actually I have three arrays: 1)values, 2)dates and 3)text descriptions in my Model. Clicking on the chart I need not value or category but the third, text in tooltip and console log in accordance with clicked or hoovered index of arrays. – user3058713 Dec 16 '13 at 12:06
-
In that fiddle I provided, you can click on bars, and it will give you the index in the console, also the data item and the series (I just verified it works) - I'm sorry, I don't understand what you're trying to do if that's not what you want. – Lars Höppner Dec 16 '13 at 13:26
-
I just follow the link and after clicking on any bar see still empty console right-bottom window both in IE and Chrome. – user3058713 Dec 16 '13 at 14:00
-
OK, the fiddle is a bit misleading - you need to actually open the console (F12 in Chrome) - in any case, you still really need to delete this answer and edit your question instead. – Lars Höppner Dec 16 '13 at 14:17
-
So complicated moderation :-) Not sure that I can join any answer to the first post correctly. – user3058713 Dec 16 '13 at 17:55
-
How to change bar chart by line series? I tried do this series: [ { type: "line", data: [1, 2, 3] }, { type: "line", data: [4, 1, -3] } ], seriesClick: onSeriesClick – user3058713 Dec 16 '13 at 18:01
For me this is what worked:
seriesClick: function (e) {
var data = e.series.data;
for (var i = 0; i < data.length ; i++) {
if (e.dataItem === data[i]) {
console.log("index " + i);
}
}

- 14,971
- 11
- 66
- 97