2014-04-18 102 views
0

我將如何去定義我希望我的圖表從中獲取數據的範圍。使用這個例子我在哪裏設置查詢範圍?我想開始建立一些圖表鏈接到我的電子表格數據的網頁。謝謝!設置查詢範圍谷歌圖表

google.load("visualization", "1", {packages:["corechart"]}); 

function initialize() { 
    var opts = {sendMethod: 'auto'}; 
    // Replace the data source URL on next line with your data source URL. 
    var query = new google.visualization.Query('http://spreadsheets.google.com/tq?key=0AnD0SFr9ooPgdG83Wm&transpose=0&headers=1&merge=COLS&range=A1%3AA5%2CB1%3AC5&gid=0&pub=1', opts);   
    - 
    // Optional request to return only column C and the sum of column B, grouped by C members. 
    //query.setQuery('select C, sum(B) group by C'); 

    // Send the query with a callback function. 
    query.send(handleQueryResponse); 
} 

function handleQueryResponse(response) { 
    if (response.isError()) { 
    alert('Error in query: ' + response.getMessage() + ' ' + response.getDetailedMessage()); 
    return; 
    } 

var data = response.getDataTable(); 

var options = { 
title: 'Company Performance' 
}; 

var chart = new google.visualization.LineChart(document.getElementById('chart_div')); 
chart.draw(data, options); 
} 

    google.setOnLoadCallback(initialize); 

回答

0

您可以選擇在查詢(通過setQuery方法)的列和過濾條件,也可以在URL的range參數中指定的片材範圍。 !

// use setQuery 
var query = new google.visualization.Query('http://spreadsheets.google.com/tq?key=0AnD0SFr9ooPgdG83Wm&transpose=0&headers=1&merge=COLS&gid=0&pub=1', opts); 
query.setQuery('select a, b, c where d < 7'); 

// set range to A1:C10 
var query = new google.visualization.Query('http://spreadsheets.google.com/tq?key=0AnD0SFr9ooPgdG83Wm&transpose=0&headers=1&merge=COLS&gid=0&pub=1&range=A1:C10', opts); 
+0

如果在工作簿內的特定片材做呢像這樣 ...&酒館= 1&範圍= Sheet 1中A1:C10' ,選擇採用); – user2970972

+0

我找到了正確的文檔,感謝您指引我朝着正確的方向發展!我是一個Java開始 – user2970972