1
如何從Google可視化查詢中告訴數據C列是字符串?我無法在文檔選項中的任何位置找到指示如何將某些列指定爲字符串或數字的選項。它認爲列C是一個數字,並且在列表圖中廣告另一列時,實際上它被設置爲一個字符串。如何在我的Google Visualization Query中將列C的值設置爲字符串?
我是在查詢選項中還是在列圖表選項中設置? 我添加了我的代碼和儀表板和數據表的圖片。
謝謝! 布蘭登
<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 bar chart,
// passes in the data and draws it.
function drawDashboard() {
var query = new google.visualization.Query(
'https://docs.google.com/a/sleschool.org/spreadsheets/d/1TRcHxsLuunRUPgn-i-h3OcVvh0TNp_VhJrNBI3ulMlA/edit#gid=0');
query.setQuery('select A,B,C');
query.send(handleQueryResponse);
}
function handleQueryResponse(response) {
if (response.isError()) {
alert('Error in query: ' + response.getMessage() + ' ' + response.getDetailedMessage());
return;
}
var data = response.getDataTable();
// Create a dashboard.
var dashboard = new google.visualization.Dashboard(
document.getElementById('dashboard_div'));
// Create a range slider, passing some options
var scoreSlider = new google.visualization.ControlWrapper({
controlType: 'NumberRangeFilter',
containerId: 'filter_div',
options: {
filterColumnLabel: 'Score'
}
});
var rtiFilter = new google.visualization.ControlWrapper({
controlType: 'CategoryFilter',
containerId: 'rtifilter_div',
options: {
'filterColumnLabel': 'RTI','ui': { 'labelStacking': 'vertical','allowTyping': true,'allowMultiple': true
}
}});
// Create a Column Bar chart, passing some options
var columnChart = new google.visualization.ChartWrapper({
chartType: 'ColumnChart',
containerId: 'chart_div',
options: {
width: 600,
height: 400,
legend: 'right',
title: 'Summative Assessment Data',
}
});
// Define a table
var table = new google.visualization.ChartWrapper({
chartType: 'Table',
dataTable: data,
containerId: 'table_div',
options: {
width: '400px'
}
});
// Establish dependencies, declaring that 'filter' drives 'ColumnChart',
// so that the column chart will only display entries that are let through
// given the chosen slider range.
dashboard.bind([scoreSlider], [table, columnChart]);
dashboard.bind([rtiFilter], [table, columnChart]);
// Draw the dashboard.
dashboard.draw(data);
}
</script>
</head>
<body>
<!--Div that will hold the dashboard-->
<div id="dashboard_div">
<h2>Summative Assessment Data</h2>
<!--Divs that will hold each control and chart-->
<div id="filter_div"></div>
<br />
<div id="rtifilter_div"></div>
<table>
<tr>
<td>
<div id="chart_div"></div>
</td>
<td>
<div id="table_div"></div>
</td>
</tr>
</table>
</div>
</body>
</html>