我想用提供的库动态生成谷歌饼图。
我有这个从mysql获取数据的代码:
$query = "SELECT name FROM mybase WHERE name = '$name' ";
$mysqli = new mysqli();
$mysqli->connect('localhost', 'blabla', 'blabla', 'blabla');
$result = $mysqli->query($query);
while ($row = $result->fetch_assoc()) {
//here I cant figure out how to make data in format for pie chart
}
我需要将此数据获取到 Java 脚本。看到 x 次表示它在数据库中列出的次数:
<html>
<head>
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load("visualization", "1", {packages:["corechart"]});
google.setOnLoadCallback(drawChart);
function drawChart() {
var data = google.visualization.arrayToDataTable([
['Name', 'Seen x times'],
['somenamefrommysql', 11],
['somenamefrommysql', 2],
['somenamefrommysql', 2],
['somenamefrommysql', 2],
['somenamefrommysql', 7]
]);
var options = {
title: 'My Daily Activities'
};
var chart = new google.visualization.PieChart(document.getElementById('chart_div'));
chart.draw(data, options);
}
</script>
</head>
<body>
<div id="chart_div" style="width: 900px; height: 500px;"></div>
</body>
</html>