3

嗨,我正在尝试从 mysql 数据库中检索数据以创建 flot pie,我的数据看起来像这样

数组中的数据

$数组 = 数组();

$Array[0] = 数组(); $Array[1] = 数组(); $Array[2] = 数组();

$Array[0]['label'] = 'A级'; $Array[1]['label'] = 'B级'; $Array[2]['label'] = 'C级';

$Array[0]['color'] = '#89A54E'; $Array[1]['color'] = '#AA4643'; $Array[2]['color'] = '#4572A7';

$Array[0]['data'][0] = array(1,700); $Array[1]['data'][0] = array(1,500); $Array[2]['data'][0] = array(1,600);

回声 json_encode($Array);

和这个mysql

$server = "localhost";
$user="root";
$password="";
$database = "db_test";

$connection = mysql_connect($server,$user,$password);
$db = mysql_select_db($database,$connection);

$query = "SELECT * FROM pie";
$result = mysql_query($query);        

while ($record = mysql_fetch_assoc($result)) {
    $event_array[] = array(
        'label' => $record['label'],
        'color' => $record['color'],
        'data' => $record['data']
    );
}

echo json_encode($event_array);

我的浮动 js

    $.ajax
({
    type:'POST', 
    dataType: 'JSON', 
    url:'data.php',
    success: function(data) 
    {    
        $.plot($('#Pie'), data, 
        {
            series: 
            {
                pie: 
                {
                    show: true,
                    innerRadius: 0.4,
                    radius: 1,
                    label: {
                        show: true,
                        radius: 1,
                        formatter: function(label, series) 
                        {
                            return "<div style='font-size:11px; text-align:center; padding:2px; color:white;'>"+label+"<br/>"
                            +Math.round(series.percent)+"%</div>";
                        },

                        background: 
                        {
                            opacity: 0.8
                        }
                    }
                }
            },

            grid: 
            {
                hoverable: true
            },

            legend: 
            {
                show: false
            }
        });
    }
});

它不会显示任何东西,有没有人可以帮助我。

4

0 回答 0