虽然数据存在,但绑定绘图饼图不可见

时间:2015-06-05 10:20:39

标签: jquery flot

我使用$ .ajax方法绑定Flot Pie Chart。在绑定时,我以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 } ] 

1 个答案:

答案 0 :(得分:1)

您的数据格式错误,flot不知道“状态”和“计数”是什么意思。

更改您的数据以使用labeldata

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