我正在努力从 MySql 表创建饼图。
我的桌子如下
buy_trader qty
TKS3G 2069
MSB1G 4417
JKB6 4021
FWS2 3507
ASI1G 2578
other 18228
我正在使用以下代码从表中生成饼图。请在这件事上给予我帮助
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Highcharts Example</title>
<?php
$con = mysql_connect("localhost","root","");
if (!$con) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db("offlinesurv", $con);
$result = mysql_query("SELECT * FROM top_buy_trades");
while($row = mysql_fetch_array($result)) {
echo $row['buy_trader'] . "\t" . $row['qty']. "\n";
}
mysql_close($con);
?>
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript">
$(function () {
var chart;
$(document).ready(function() {
chart = new Highcharts.Chart({
chart: {
renderTo: 'container',
plotBackgroundColor: null,
plotBorderWidth: null,
plotShadow: false
},
title: {
text: 'Top Buy Traders'
},
tooltip: {
pointFormat: '{series.name}: <b>{point.percentage}%</b>',
percentageDecimals: 1
},
plotOptions: {
pie: {
allowPointSelect: true,
cursor: 'pointer',
dataLabels: {
enabled: true,
color: '#000000',
connectorColor: 'green',
formatter: function() {
return '<b>'+ this.point.name +'</b>: '+ this.percentage +' %';
}
}
}
},
series: [{
type: 'pie',
name: 'Broker share',
data: [<?php echo $row ?>]
}]
});
});
});
</script>
</head>
<body>
<script src="js/highcharts.js"></script>
<script src="js/exporting.js"></script>
<div id="container" style="min-width: 400px; height: 400px; margin: 0 auto"></div>
</body>
</html>
请帮我解决这个问题。因为我一段时间以来一直在努力解决这个问题。
请问这段代码有什么问题