这是我的HTML代码:
google.load('visualization', '1', {'packages':['Table']});
// Set a callback to run when the Google Visualization API is loaded.
google.setOnLoadCallback(drawChart);
function drawChart() {
var jsonData = $.ajax({
url: "http://localhost:8080/getData.php",
dataType:"json",
async: false
}).responseText;
var myArr = $.parseJSON(jsonData);
// Create our data table out of JSON data loaded from server.
var data = new google.visualization.DataTable(myArr);
data.addRows(myArr.length);
data.addColumn('string','emp_name');
data.addColumn('string','works_on');
data.addColumn('datetime','time_from');
data.addColumn('datetime','time_to');
data.addColumn('number','Number of Hours');
$.each(myArr, function(i,d) {
data.setValue(i,0,d.emp_name);
data.setValue(i,1,d.works_on);
data.setValue(i,2,new Date(d.time_from));
data.setValue(i,3,new Date(d.time_to));
});
var formatter3 = new google.visualization.DateFormat({pattern: "d-MM-yyyyTHH:mm:SS"});
formatter3.format(data,2);
formatter3.format(data,3);
// Instantiate and draw our chart, passing in some options.
var chart = new google.visualization.Table(document.getElementById('chart_div'));
chart.draw(data,null);
}
我想通过计算每个员工的总工作时间绘制一个饼图(例如:" ABC-10hr,xyz-5hr"等等)。到目前为止,我已经完成了这么多工作并请帮助我在策划部分。