2015-03-30 47 views
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>

Data Sheet Dashboard Output.

回答

0

我这样还没有建立数据表之前,但你可以尝试使用setColumnProperty

我不知道,如果类型可以在创建后可以改变,但它是值得一试的尝试是这样的:

data = response.getDataTable(); 
data.setColumnProperty(colIndex, "type", "string"); 
相关问题