admin管理员组

文章数量:1405631

Any method that can get sum, avg, count of data at a column in google chart table? I want to show metadata of that table out of the table.

Any method that can get sum, avg, count of data at a column in google chart table? I want to show metadata of that table out of the table.

Share Improve this question edited Feb 5, 2013 at 10:19 vidya sagar 2,0093 gold badges18 silver badges18 bronze badges asked Feb 5, 2013 at 10:12 Dinuka ThilangaDinuka Thilanga 4,33010 gold badges58 silver badges94 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 3

Alternatively, if you have a DataTable you manually input, you can do the same as follows:

function drawVisualization() {
  // Create and populate the data table.
  var data = google.visualization.arrayToDataTable([
    ['x', 'Cats'],
    ['A',   1],
    ['B',   2],
    ['C',   4],
    ['D',   8],
    ['E',   7],
    ['F',   7],
    ['G',   8],
    ['H',   4],
    ['I',   2],
    ['J',   3.5],
    ['K',   3],
    ['L',   3.5],
    ['M',   1],
    ['N',   1]
  ]);

  // Create an Array to hold column data
  var tmpColumn = new Array();

  // Add each data value to the array with push()
  for(var i = 0; i < data.getNumberOfColumns(); ++i) {
    tmpColumn.push(data.getValue(i, 1));
  }

  // Use built-in Google Functions on the array
  alert(google.visualization.data.avg(tmpColumn));
  alert(google.visualization.data.sum(tmpColumn));
  alert(google.visualization.data.count(tmpColumn));
}

Perhaps you are looking for something like this:

var query = new google.visualization.Query(DATA_SOURCE_URL);
query.setQuery('select dept, sum(salary) group by dept');
query.send(handleQueryResponse);  

DATA_SOURCE_URL can correspond to a Google Chart Data Source URL.

From: https://developers.google./chart/interactive/docs/querylanguage

本文标签: javascriptGet sum of column in google chart tableStack Overflow