Rafa Romero
Rafa Romero

Reputation: 2716

Google Charts Api - Select specific column to draw

I'm working with Google Charts Api.

As a data surce, I'm using a Google spreeadsheat. I using this spreadsheat:

https://docs.google.com/spreadsheet/pub?key=0Amf7cOIp81pxdGdxUmFMZVVFVjBwTENTcUpVVldVRnc&output=html

The problem is that as the table has multiple columns, how can I select which column I wnat to show in the chart?

I get the table via: var data = response.getDataTable(); But I don't know hot to get some column from data.

In draw() method I don't know too if I can pass as parameter some specific column

Here my complete code:

google.load('visualization', '1.0', {'packages':['corechart']});
google.load('visualization', '1.0', {'packages':['controls']});

google.setOnLoadCallback(drawChart);

function drawChart() {
  var query = new google.visualization.Query(
      'https://docs.google.com/spreadsheet/pub?key=0Amf7cOIp81pxdGdxUmFMZVVFVjBwTENTcUpVVldVRnc&output=html');

  query.send(handleQueryResponse);
}

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

  var data = response.getDataTable();

    // Testing
    console.log(data.getColumnId(1));  


  var chart = new google.visualization.PieChart(document.getElementById('columnchart'));

  var options = {'title':'World Cup Statistics',
                 'width':800,
                 'height':800};


  chart.draw(data, options);

Upvotes: 0

Views: 2361

Answers (1)

asgallant
asgallant

Reputation: 26340

Use the setQuery method of the Query object:

query.setQuery('select A, B, C');

Use the letter ID's of the columns you want to select in the query. Documentation on the query language is here.

Upvotes: 1

Related Questions