有谁知道如何将信息中心绑定到Google电子表格的范围内?
在我目前的代码中,我假设仪表板可以绑定到Google Spreadsheet的范围,就像这样,但是setDataTable函数调用让我很难。
从工作表名称和时间中仅选择两列。
<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 controls package.
google.load('visualization', '1.0', {'packages':['controls']});
// Set a callback to run when the Google Visualization API is loaded.
google.setOnLoadCallback(drawDashboard);
// Callback that creates and populates a data table,
// instantiates a dashboard, a range slider and a pie chart,
// passes in the data and draws it.
function drawDashboard() {
// Create our data table.
var data = google.visualization.arrayToDataTable([
['Name', 'Donuts eaten'],
['Michael' , 5],
['Elisa', 7],
['Robert', 3],
['John', 2],
['Jessica', 6],
['Aaron', 1],
['Margareth', 8]
]);
// Create a dashboard.
var dashboard = new google.visualization.Dashboard(
document.getElementById('dashboard_div'));
// Create a range slider, passing some options
var donutRangeSlider = new google.visualization.ControlWrapper({
'controlType': 'NumberRangeFilter',
'containerId': 'filter_div',
'options': {
'filterColumnLabel': 'Donuts eaten'
}
});
// Create a pie chart, passing some options
var pieChart = new google.visualization.ChartWrapper({
'chartType': 'PieChart',
'containerId': 'chart_div',
'options': {`enter code here`
'width': 300,
'height': 300,
'pieSliceText': 'value',
'legend': 'right'
}
});
// Establish dependencies, declaring that 'filter' drives 'pieChart',
// so that the pie chart will only display entries that are let through
// given the chosen slider range.
dashboard.bind(donutRangeSlider, pieChart);
// Draw the dashboard.
dashboard.draw(data);
}
</script>
</head>
<body>
<!--Div that will hold the dashboard-->
<div id="dashboard_div">
<!--Divs that will hold each control and chart-->
<div id="filter_div"></div>
<div id="chart_div"></div>
</div>
</body>
</html>
答案 0 :(得分:0)
那么,你想要的只是将名称/时间转换为dataTable? 你必须在谷歌服务器中转换数组,返回HTML页面然后转换为dataTable,如下:
在code.gs
中function getTimes(){
var playTimes = SpreadsheetApp.openById("1csv3OQ0IrVNyNIALcpqoLewccgYEEwErsS-Tp43IZfQ").getSheetByName("players").getRange("B1:E").getValues();
for( i in playTimes ){
playTimes[i] = [ playTimes[i].splice(0, 1)[0], playTimes[i].splice(2, 1)[0] ];
}
return playTimes;
}
HTML页面中的 - &gt;将google.setOnLoadCallback(drawDashboard);
更改为google.setOnLoadCallback(loadPlayTimes);
,同时将function drawDashboard()
更改为function drawDashboard( playTimes )
以接受参数:
function loadPlayTimes(){
google.script.run.withSuccessHandler(drawDashboard).getTimes();
}
并创建dataTable:
var data = google.visualization.arrayToDataTable( playTimes );