如何将数据绑定到donut kendo组件



我试图将数据绑定到甜甜圈剑道组件。到目前为止,我的工作低于

js文件:

function createChart() {
$("#chart").kendoChart({
dataSource: {
transport: {
read: {
url: "/ert.mvc/Summary?id=23",
dataType: "json",
type: "GET"
}
}
},
title: {
position: "bottom",
text: "Share of Internet Population Growth"
},
legend: {
visible: false
},
series: [{
data: [{
type: "donut",
field: "newlyRequested",
categoryField: "source",
explodeField: "explode"                        },
{
type: "donut",
field: "pending",
categoryField: "source",
explodeField: "explode"                               
}]
}],
seriesColors: ["#42a7ff", "#666666"],
tooltip: {
visible: true,
template: "#= category # (#= series.name #): #= value #%"
}
});
}

我的api响应如下:-

{
total: 120,
pending: 25,
incomplete: 10,
newlyRequested: 10
}

我遵循https://demos.telerik.com/kendo-ui/donut-charts/donut-labels的例子。但我得到kendo.all.js:7786未捕获的TypeError: e.s slice不是一个函数错误。我的预期结果是我想显示甜甜圈图与未决,不完整…

有什么想法吗

首先,您的API响应错误。它应该是一个像这样的对象数组:

[ 
{type: "total", value: 120},
{type: "pending", value: 25},
{type: "incomplete", value: 10},
{type: "newlyRequested", value: 10}
]

根据上面的API响应,您必须更改您的series配置。最后,您的甜甜圈图配置应该如下所示:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>Kendo UI Snippet</title>
<link rel="stylesheet" href="https://kendo.cdn.telerik.com/2021.3.914/styles/kendo.default-v2.min.css"/>
<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<script src="https://kendo.cdn.telerik.com/2021.3.914/js/kendo.all.min.js"></script>
</head>
<body>
<div id="chart"></div>
<script>
$("#chart").kendoChart({
dataSource: [
{type: "total", value: 120},
{type: "pending", value: 25},
{type: "incomplete", value: 10},
{type: "newlyRequested", value: 10}
],
title: {
position: "bottom",
text: "Share of Internet Population Growth"
},
legend: {
visible: false
},
series: [{
type: "donut",
field: "value",
categoryField: "type",
}],
seriesColors: ["#42a7ff", "#666666"],
tooltip: {
visible: true,
template: "#= category # (#= kendo.format('{0:P}', percentage) #): #= value #"
},
seriesDefaults: {
labels: {
template: "#= category # - #= kendo.format('{0:P}', percentage)#",
position: "outsideEnd",
visible: true,
background: "transparent"
}
},
});
</script>
</body>
</html>

我已经添加了一个系列标签,并修改了工具提示,使图表看起来更好。你可能想在这里看更多的图表示例。

最新更新