This is a migrated thread and some comments may be shown as answers.

Chart point dataItem issue

2 Answers 64 Views
Charts
This is a migrated thread and some comments may be shown as answers.
James
Top achievements
Rank 1
James asked on 24 Apr 2014, 06:07 PM
In KendoUI chart, when aggregating series data for a category, one would expect that the dataItem for the point would contain all the actual data points used to construct that dataItem. Since the point on the graph is an aggregate, its reasonable to assume that more than one piece of data was used to construct it.

For example, given the series data:
                   [
                      {'Operation': 'A', 'Cost': 2.5, 'StartTime':'2014-04-02T00:00:00-07:00'},
                      {'Operation': 'B', 'Cost': 2.5, 'StartTime':'2014-04-02T00:00:00-07:00'},
                      {'Operation': 'C', 'Cost': 3, 'StartTime':'2014-04-03T00:00:00-07:00'},
                      {'Operation': 'D', 'Cost': 3, 'StartTime':'2014-04-03T00:00:00-07:00'}    
                    ]

Where categoryField is 'StartTime',  (value) field is 'Cost' and aggregate is 'sum',  we can then assume that we will have 2 data points on the graph:

2014-04-02 = 5
2014-04-03 = 6

When we look at the dataItem for the first point (in a tooltip for example), we would assume that somehow 'A' and 'B' would be represented.  However the data point looks like 'A', with 'Cost' set to the aggregate of A+B.

So it seems instead of returning the set of items in the point aggregate, kendo is doing some sort of weird merging of the point (probably just taking the first) and merging in the aggregate.

Take a look at this example, when hovering the chart item, look at the console output for the dataItem.   Also note series.data is now missing B and D respectively.

http://trykendoui.telerik.com/@jsconnell@2ndwatch.com/ASEM

Am I wrong to make this assumption, or is this a bug?

2 Answers, 1 is accepted

Sort by
0
T. Tsonev
Telerik team
answered on 28 Apr 2014, 12:43 PM
Hello,

Your analysis of the aggregate implementation is pretty much spot on.
We create a new object that holds the aggregated field value(s) and "inherit" (set its prototype) to the first data item.

This is done mostly for performance considerations. Copying and merging data items has a cost when you have 60000 points for example.
We're also a bit reluctant to carry a reference to the original data items, as this will take up some memory.

This is likely not a problem in your scenario, so you can create a custom aggregate and build the data item as needed:
      series: [{
        aggregate: function(values, series, dataItems, category) {
          var operations = $.map(dataItems, function(d) {
            return d.Operation;
          });
          
          return {
            Operations: operations,
            // ...
          };
        }
      }]


-- Live demo --

I hope this helps.

Regards,
T. Tsonev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
James
Top achievements
Rank 1
answered on 30 Apr 2014, 08:35 PM
Thank you for the detailed response, the custom aggregate is pretty much exactly what I need in this case.  
Tags
Charts
Asked by
James
Top achievements
Rank 1
Answers by
T. Tsonev
Telerik team
James
Top achievements
Rank 1
Share this question
or