我试图用聚合函数制作饼图。它应该显示该类别中的类别名称和产品计数。我不知道如何找到类别的产品数量。
如何找到它们?感谢。
import scala.annotation.tailrec
object FuncSelectionSort {
/**
* Selection Sort - Trying Functional Style
*/
def sort(a: Array[Int]) = {
val b: Array[Int] = new Array[Int](a.size)
Array.copy(a, 0, b, 0, a.size)
// Function to swap elements
def exchange(i: Int, j: Int): Unit = {
val k = b(i);
b(i) = b(j);
b(j) = k;
}
@tailrec
def helper(b: Array[Int], n: Int): Array[Int] = {
if (n == b.length-1) return b
else {
val head = b(n);
val minimumInTail = b.slice(n, b.length).min;
if (head > minimumInTail) {
val minimumInTailIndex = b.slice(n, b.length).indexOf(minimumInTail);
exchange(n, minimumInTailIndex + n);
}
helper(b, n + 1)
}
}
helper(b, 0)
}
}

var dataSource = new kendo.data.DataSource({
type: "odata",
transport: {
read: "//demos.telerik.com/kendo-ui/service/Northwind.svc/Categories"
},
});
$("#chart").kendoChart({
dataSource: dataSource,
legend: {
visible: true
},
seriesDefaults: {
type: "pie"
},
series: [{
field: "CategoryID", //it should be product count by category
categoryField: "CategoryName",
explodeField: "explode",
labels: {
visible: true,
}
}],
});

答案 0 :(得分:1)
以这种方式试试,
var dataSource = new kendo.data.DataSource({
type: "odata",
transport: {
read: "//demos.telerik.com/kendo-ui/service/Northwind.svc/Categories?$expand=Products"
},
});
$("#chart").kendoChart({
dataSource: dataSource,
legend: {
visible: true
},
series: [{
type: "pie",
field: "Products.results.length",
categoryField: "CategoryName",
explodeField: "explode",
labels: {
visible: true,
}
}]
});
Read up on odata expand并计算标量导航属性以获得更精细的