0
안녕하세요 저는 처음으로 jqplot을 사용하고 있습니다. 데이터베이스에서 데이터를 가져 와서 파이 차트를 표시해야합니다. 내가 쿼리를 작성하고 json 테이블의 데이터를 변환하는 데 문제가 있습니다. 그래프를 생성 할 수 없습니다. 제발 도와주세요. 제 코드입니다.jqplot에 관한 내용은 PHP에서 SQL 서버의 데이터가있는 원형 차트를 플로팅합니다.
PHP 코드
<?php require_once('Connections/finalkms.php');
mysql_select_db($database_finalkms, $finalkms);
$query_getdatagraoh = "SELECT Compliancestatus,value FROM COUNT_VALUE WHERE Zone='PZ' and country='AU' and `Compliancestatus` is not null";
$getdatagraoh = mysql_query($query_getdatagraoh, $finalkms) or die(mysql_error());
$row_getdatagraoh = mysql_fetch_assoc($getdatagraoh);
$totalRows_getdatagraoh = mysql_num_rows($getdatagraoh);
while($row = mysql_fetch_assoc($getdatagraoh)){
$plotgraphs[] = array(
$row['Compliancestatus'],
$row['value']
);
}
header('ContentType: application/json; charset=utf-8');
$data= json_encode($plotgraphs);
?>
자바 스크립트
<script>
$(document).ready(function(){
var data1 = <?php echo json_encode($plotgraphs); ?>;
alert(data1);
var plot1 = jQuery.jqplot ('chart1', [data1],
{
seriesDefaults: {
// Make this a pie chart.
renderer: jQuery.jqplot.PieRenderer,
rendererOptions: {
// Put data labels on the pie slices.
// By default, labels show the percentage of the slice.
showDataLabels: true
}
},
legend: { show:true, location: 'e' }
}
);
});
</script>
HTML
<div id="chart1"></div>