我有一张工作人员不同时间的表格(教学时间,服务时间和研究时间)。我需要绘制员工的条形图和饼图,但x轴和图例只是几个小时的重复
sql语句后来自sql的数据示例
$query ="SELECT teachinghours,servicehours,researchhours
FROM staff_hour sh,staff s
WHERE s.staffid = sh.staffid
AND `staffperiodyear`= 'FY2018'
AND s.staffid in (SELECT s.staffid from staff s where s.username = '$staffid1')";
$res=mysqli_query($connect,$query);
| teachinghours | servicehours | researchhours |
|---------------------|------------------|-----------------|
| 1379 | 99 | 247 |
|---------------------|------------------|-----------------|
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript">
google.charts.load('current',{'packages':['bar']}).then(function() {
google.charts.load('current',{'packages':['bar']}).then(function() {
var barsButton = document.getElementById('b1');
var pieButton = document.getElementById('b2');
barsButton.onclick = function() {
drawSarahChart('ColumnChart');
}
pieButton.onclick = function() {
drawSarahChart('PieChart');
}
drawSarahChart('ColumnChart');
});
function drawSarahChart(chartType) {
var chart = new google.visualization.ChartWrapper({
containerId: 'Sarah_chart_div'});
var data = google.visualization.arrayToDataTable([
['teachinghours','Hour'],<?php
while($row=mysqli_fetch_array($res))
{
echo "['".$row["servicehours"]."',".$row[1]."],";
echo "['".$row["teachinghours"]."',".$row[0]."],";
echo "['".$row["researchhours"]."',".$row[2]."],";}
?>]);
var options = {
title: 'FY 2018',width: 400,height: 300,legend: { position: 'top',alignment: 'start' },tooltip: { isHtml: true }
};
chart.setOptions(options);
chart.setChartType(chartType);
chart.setDataTable(data);
chart.draw();