我正在使用谷歌图表,我需要从 PHP 文件(或 HTML 文件中的 php?)中获取数据以将数据提供给图表。那么我将如何做到这一点,并确保在绘制图表之前获取数据。我已经在研究如何使用 PHP 从 Mysql 数据库中获取数据
这是我需要放入 vars 的代码
<html>
<head>
<!--Load the AJAX API-->
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
// Load the Visualization API and the piechart package.
google.load('visualization', '1.0', {'packages':['corechart']});
// Set a callback to run when the Google Visualization API is loaded.
google.setOnLoadCallback(drawChart);
// Callback that creates and populates a data table,
// instantiates the pie chart, passes in the data and
// draws it.
function drawChart() {
// Create the data table.
var data = new google.visualization.DataTable();
data.addColumn('string', 'Color');
data.addColumn('number', 'Votees ');
data.addRows([
['Value from Mysql', 3000],
['Value2 from Mysql', 13000],
]);
// Set chart options
var options = {'title':'Table Name From MySql',
'width':600,
'height':450};
// Instantiate and draw our chart, passing in some options.
var chart = new google.visualization.PieChart(document.getElementById('chart_div'));
chart.draw(data, options);
}
</script>
</head>
<body>
<!--Div that will hold the pie chart-->
<div id="chart_div"></div>
</body>
</html>