Displaying chart data from a database

假装没事ソ 提交于 2019-12-13 05:22:23

问题


Im following the instructions in http://docs.highcharts.com/#preprocessing-data-from-a-database to display some data comming from a database using php PDO and mysql but i only get slices when i show the chart.. this is my code

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);

// This is the output with the 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:


Please familair with article about preprocessing data http://docs.highcharts.com/#preprocessing , you can also use json_encode()



来源:https://stackoverflow.com/questions/17181462/displaying-chart-data-from-a-database

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!