gpt4 book ai didi

jquery - 绑定(bind) Flot 饼图时,即使数据存在,它也不可见

转载 作者:行者123 更新时间:2023-12-01 04:45:25 24 4
gpt4 key购买 nike

我使用 $.ajax 方法绑定(bind) Flot 饼图。绑定(bind)时我正在获取 json 格式的数据并使用 $.plot 方法。但之后我看不到正在绘制的饼图。下面是我的代码:

    function drawPieChart() {
$.ajax({
type: "POST",
url: "Api/ChartsApi.aspx",
data: '{}',
contentType: "application/json;charset=utf-8",
dataType: "json",
success: function (r) {
if (r != null) {
data = r;
DrawPieChart();

}
else {
alert("No Data Avaliable");
return false;
}
},
failure: function (r) {
alert(r.d);
},
error: function (r) {
alert(r.d);
}
});
}

//Pie Chart
function DrawPieChart() {
$.plot($("#placeholder"), data, {
series: {
pie: {
show: true
}
},
legend: {
labelBoxBorderColor: "none"
}
});
}

数据如下:

[ { "Status": "Active", "Count": 28 }, { "Status": "Under Process", "Count": 15 }, { "Status": "Registered", "Count": 23 } ] 

最佳答案

您的数据格式错误,flot 不知道“Status”和“Count”的含义。

更改数据以使用标签数据:

[ 
{ label: "Active", data: 28 },
{ label: "Under Process", data: 15 },
{ label: "Registered", data: 23 }
]

关于jquery - 绑定(bind) Flot 饼图时,即使数据存在,它也不可见,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30664117/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com