jqPlot绘制饼图问题

时间:2012-08-02 10:07:51

标签: javascript jquery html jqplot

我遇到了下一个问题:当我获取数据并尝试构建jqPLot PieChart时,萤火虫说uncaught exception: No Data 这是我的数据检索功能:

function getValues(){
        var myArr=[];

        $.ajax({
                type : "POST",
                url : myUrl,
                data : {

                },
                success : function(response) {
                    for ( var i = response.myList.length - 1; i >= 0; --i) {
                        var obj = response.myList[i];
                        var id = obj.id;
                        var name = obj.name;
                        var value = obj.value;

                        ......some code here....
                        myArr.push[{name:value}];

                    }
                },

                error : function(response) {
                    alert("your request cannot be handled. " + response);
                }
            });
            drawPieChart(myArr);
}

这是我的drawPieChart函数:

function drawPieChart(array) {
     var plot1 = jQuery.jqplot ('chartdiv', [array], 
                { 
                  seriesDefaults: {
                    // Make this a pie chart.
                    renderer: jQuery.jqplot.PieRenderer, 
                    rendererOptions: {
                      // Put data labels on the pie slices.
                      // By default, labels show the percentage of the slice.
                      showDataLabels: true
                    }
                  }, 
                  legend: { show:true, location: 'e' }
                }
              );
}

这里是html源码,我想插入我的PieChart:

<div id="chartdiv" style="height:400px;width:300px; "></div>

所以有人可以帮我解决这个问题吗?我做错了什么? jqPlot的所有文件都已正确连接。

2 个答案:

答案 0 :(得分:0)

jqPlot只接受[[[[X,Y],...]]

所以将myArr.push({name:value})更改为myArr.push([name,value])

请参阅http://www.jqplot.com/deploy/dist/examples/pie-donut-charts.html

答案 1 :(得分:0)

您输入数据的方式是错误的,请尝试如下编码:

var data = [
['Heavy Industry', 12],['Retail', 9], ['Light Industry', 14], 
['Out of home', 16],['Commuting', 7], ['Orientation', 9]]

使用一些简单的值,看看是否可以运行它,如果它工作,那么解决它。

相关问题