KendoUI - DataViz - Grouping and Aggregating a JSO

2019-07-22 19:18发布

I've been able to accomplish such grouping in certain charts and not others. For example, assume that I have a datasource that looks something like this:

var pictures = [
  { type: "JPG", len: 20, wid: 15, appr: 17.5, count: 2 },
  { type: "JPG", len: 22, wid: 17, appr: 12.5, count: 3 },
  { type: "JPG", len: 24, wid: 15, appr: 10.5, count: 1 },
  { type: "JPG", len: 22, wid: 4, appr: 17.5, count: 6 },
  { type: "PNG", len: 20, wid: 15, appr: 17.5, count: 4 },
  { type: "PNG", len: 25, wid: 7, appr: 9.5, count: 4 },
  { type: "PNG", len: 21, wid: 11, appr: 21.5, count: 1 }
];

I want to group by my category which in this case is "type", I want to sum all other fields.

I am able to do this quite simply with column charts, simply by setting:

series: [{aggregate: "sum",categoryField: "type"}]

However, this does not work with bullet or pie charts, so in search of a more universal method. I "massage" the data first by adding this at the beginning:

var dataSource = new kendo.data.DataSource({
  data: pictures,
  group: {
    field: "type",
    aggregates: [
        { field: "len", aggregate: "sum" },
        { field: "wid", aggregate: "sum" }
    ]
  }
});

dataSource.read();

I don't know why just grouping the datasource like so isn't enough.. I have to throw it into arrays and assign each array to a series like so:

var seriesA = [],
  seriesB = [],
  categories = [],
  items = dataSource.view(),
  length = items.length,
  item;

for (var i = 0; i < length; i++) {
  item = items[i];

  seriesA.push(item.aggregates.wid.sum);
  seriesB.push(item.aggregates.len.sum);
}

This works as long as having only one valueField per series works. In the case of a bullet chart, or if I want to assign a field to a plotband to a bar/column chart: it does not.

I believe I must be doing something completely wrong, as converting my ungrouped JSON object to a grouped kendo datasource should be enough. Below is my JSFiddle..

http://jsfiddle.net/DxMb8/4/

Any help would be greatly appreciated! thanks!

0条回答
登录 后发表回答