我们可以在弹出的花式框中绘制谷歌图表吗?
我在表格中显示了数据,每一行都有一个按钮用于显示每条记录的谷歌图表。
目前,我的图表总是显示在表格之后的底部,但是当记录在屏幕上滚动时,用户需要滚动到底部才能获得图表视图。是否可以使用fancybox或某种方式解决这个不方便?
感谢您的任何建议!
html:
<table>
<tr>
<td> data </td>
...
<td>
<button onclick="showChartByEmpId()"> pie chart </button>
</td>
</tr>
</table>
<div class="secondary"> </div> <!-- showing chart here -->
js:
function drawPieChart(dataArr, elementId) {
//dataArr : the data to display
//elementId : <div> element where to display chart
var data = google.visualization.arrayToDataTable(dataArr);
var chart = new google.visualization.PieChart(document.getElementById(elementId));
chart.draw(data, options);
}
function showChart(){
//alert("readyState=" + xhr2.readyState);
if(xhr2.readyState == 4) {
if(xhr2.status == 200){
var allEmp = xhr2.responseText;
var empList = JSON.parse(allEmp);
... prepare pieChartDate[] to draw chart ...
//create <div> to displaying chart in it
$('.secondary').html('<div id="chart_div" height="450" width="450"></div>');
drawPieChart(pieChartData[0], "chart_div");
...
}
function showChartByEmpId(){
var url = '/CMP/employee/emp.do';
//create XMLHttpRequest
xhr = createXHR();
if( xhr == null ){
alert("no xhr creted");
return;
}
var requestData = "action=getOneEmpJSON&empId1=" + escape(empId1) + "&empId2=" + escape(empId2);
xhr.open('POST', url, true);
xhr.onreadystatechange = showChart;
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.send(requestData);
}