1

我有以下代码来呈现条形图和饼图。两者都从服务器接收相同的 JSON 数据集,如下所示:A:115.00 B:55.00 C:0.00 D:29.04

由于某些原因,条形图能够呈现它。但饼图没有显示任何内容。

var AjaxDataRenderer = function(url, plot, options) {
    var ret;
    $.ajax({
        async: false, // Needed
        url: "getData.php",
        dataType:"json",
        success: function(data) { 
            ret = data;
        }
    });
    return ret;
};

var plot = $.jqplot('id-BarChart', [],{
    title: "TRIAL",
    dataRenderer: AjaxDataRenderer,
    seriesDefaults:{
        renderer:$.jqplot.BarRenderer,
        rendererOptions: {fillToZero: true}
    },
    series:[{color:'#5FAB78',label:"Actual"}],
    legend: {
        show: true, 
        placement: "insideGrid", 
        rendererOptions: { 
            textColor: "#FFFFFF", 
            fontSize: "10pt" 
        }},
    axes: {
        xaxis: {
            renderer: $.jqplot.CategoryAxisRenderer,
            tickRenderer: $.jqplot.CanvasAxisTickRenderer ,
            tickOptions: {
                angle: -30,
                fontSize: '10pt'
            }
        },
        yaxis: {
            min: 10,
            max: 300,
            tickOptions: {
                formatString: '$%d'
            }
        }
    }
});

var plot = $.jqplot('id-PieChart', [],{
    dataRenderer: AjaxDataRenderer,
    title: 'Expenditure pattern for this session',
    seriesDefaults: {
        renderer: jQuery.jqplot.PieRenderer, 
        rendererOptions: {
            padding: 8,          
            showDataLabels: true
            }
    }, 
});

有人可以帮忙吗?

4

1 回答 1

0

做了一些调试,发现了以下作品。

这是我拥有的 PHP 代码:

$rows = array();
$rows1 = array();
$j = 1;
while($category = mysql_fetch_assoc($allCategories))
{
$current = 0 + $category['ExpenditureCurrent']; 
$toDate = 0 + $category['ExpenditureToDate'];       
$j += 1;    
$rows[] = array($category['Name'], $toDate);
$rows1[] = array($category['Name'], $current);
}
echo json_encode(array($rows,$rows1));

由于某些原因,条形图适用于这些:

    $current = $category['ExpenditureCurrent']; 
    $toDate = $category['ExpenditureToDate'];       

虽然饼图需要这些:

    $current = 0 + $category['ExpenditureCurrent']; 
    $toDate = 0 + $category['ExpenditureToDate'];       
于 2012-05-16T01:22:32.247 回答