问题
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