显示数据库中的图表数据

时间:2013-06-19 01:16:13

标签: php jquery mysql pdo highcharts

我按照http://docs.highcharts.com/#preprocessing-data-from-a-database中的说明显示使用php PDO和mysql从数据库传来的一些数据,但是当我显示图表时我只得到切片..这是我的代码

MODEL

  public function get_proyectos_service_por_id($idproject) {

    $sql = "SELECT p.id_project, s.service_type, s.completion_status, s.id_service, sp.id_projectserv

    FROM projects p
    LEFT JOIN project_serv sp ON p.id_project = sp.id_project
    LEFT JOIN services s ON sp.id_service = s.id_service 
    WHERE p.id_project = ?";

    $stmt = $this->dbh->prepare($sql);

    $stmt->bindParam(1, $idproject, PDO::PARAM_INT);
    $stmt->execute();

    $rows = array();

    foreach( $stmt->fetchAll(PDO::FETCH_ASSOC) as $row ){ 

     $rows[] = array("service" =>$row['service_type'], "status" =>$row['completion_status']); 

 } 

 return $rows;
}

 // Now i call this method

 $project = new Proyecto();
 $serv = $project->get_proyectos_service_por_id($pro);

//这是JS

的输出
$(function () {
                var options = {
                    chart: {
                        renderTo: 'chart_div',
                        defaultSeriesType: 'pie'
                    },
                    title: {
                        text: 'Datos de proyecto'
                    },

                    series: [{
                        data: [<?php echo implode(",", $serv); ?>]

                    }]
                };
                new Highcharts.Chart(options);  
            });

1 个答案:

答案 0 :(得分:0)

请熟悉有关预处理数据http://docs.highcharts.com/#preprocessing的文章,您也可以使用json_encode()