0

我有下面的代码来呈现一个 jqplot 饼图。由于某些原因,饼图未正确显示百分比。

$array= array(array("Males", $males),array("Female", $females));
json_encode($array);

json文件的输出为:

[["Books","8"],["Female","0"]]

但是饼图的显示显示的是 10% 而不是 100,这是我的饼图渲染器

$.getJSON('jqPlot.php', function (data) {

        var plot1 = jQuery.jqplot('chart1', [data], {
            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' }});
    });
});

但是,如果我将 json 文件更改[["Books","8"]]为饼图,则可以正常工作。

4

1 回答 1

0

试试这个,工作正常。

$.getJSON(url, function(data) {
    var items1 = new Array();
    var j=0;
    for ( var i in data ) {
        var items = new Array();
        items.push(i,Number(data[i]));
        items1[j++] = items;
    }

    var plot1 = jQuery.jqplot('chart1', eval([items1]), {

                seriesDefaults:{
                    renderer:jQuery.jqplot.PieRenderer,
                    rendererOptions:{
                        dataLabels:'value',
                        showDataLabels:true
                    }
                },
                legend:{ show:true, location:'e' }
            }
    );

});
于 2013-09-04T12:03:46.963 回答