我使用下面的代碼來生成餅圖。但我得到一個空白頁而不是圖表。PHP和Highcharts
但是在控制檯中找不到任何錯誤。
如何找到缺少的東西?如何在這種情況下調試我的代碼?
<?php
$servername = "localhost";
$username = "root";
$password = "";
$conn = new mysqli($servername, $username, $password);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$query = "SELECT name, val FROM wfss.web_marketing";
$result = mysqli_query($conn , $query);
if ($result) {
echo "</br>"."Results Found";
// Conversion of result object into JSON format
$rows = array();
while($r = mysqli_fetch_array($result,MYSQLI_NUM)) {
$row[0] = $r[0];
$row[1] = $r[1];
array_push($rows,$row);
}
print json_encode($rows, JSON_NUMERIC_CHECK);
} else {
echo "No Results Found";
}
mysqli_close($conn);
?>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script src="http://code.highcharts.com/highcharts.js"></script>
<script src="http://code.highcharts.com/modules/exporting.js"></script>
<script type="text/javascript">
$(document).ready(function() {
var options = {
chart: {
renderTo: 'container',
plotBackgroundColor: null,
plotBorderWidth: null,
plotShadow: false
},
title: {
text: 'Web Sales & Marketing Efforts'
},
tooltip: {
formatter: function() {
return '<b>'+ this.point.name +'</b>: '+ this.percentage +' %';
}
},
plotOptions: {
pie: {
allowPointSelect: true,
cursor: 'pointer',
dataLabels: {
enabled: true,
color: '#000000',
connectorColor: '#000000',
formatter: function() {
return '<b>'+ this.point.name +'</b>: '+ this.percentage +' %';
}
}
}
},
series: [{
type: 'pie',
name: 'Browser share',
data: [<?php echo json_encode($rows)?> ]
}]
}
});
</script>
<div id="container" style="min-width: 400px; height: 400px; margin: 0 auto"></div>
代碼丟失 – Miuranga
請你解釋一下。我是新手到PHP @ miuranga – Rama
你需要與你的 「選項」 變種爲前VAR圖表創建highcharts =新Highcharts.StockChart( \t \t \t \t \t \t \t \t \t \t \t \t選項); –