簡體   English   中英

如何在Google可視化查詢中將C列的值設置為字符串?

[英]How can I set the value of column C as a string in my Google Visualization Query?

如何從Google可視化查詢中得知數據C列是字符串? 我在文檔選項中找不到任何地方可以向我展示如何將某些列指定為字符串或數字。 它認為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> 

數據表儀表板輸出。

我以前沒有以這種方式構建過DataTables,但是您可以嘗試使用setColumnProperty

我不知道創建后是否可以更改類型,但是值得嘗試一下這樣的嘗試:

data = response.getDataTable();
data.setColumnProperty(colIndex, "type", "string");

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM