سؤال

How would I go about defining the range I want my chart to grab data from. Using this example where do I set query range? I would like to start building some webpages with charts linking to my spreadsheet data. Thank you!

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);
هل كانت مفيدة؟

المحلول

You can either select the columns and filter criteria in the query (via the setQuery method), or you can specify a sheet range in the range parameter of the URL.

// 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');

or

// 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);
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top