任何可以在sum
的列中获取avg
,count
,google chart table
数据的方法?我想在表格中显示该表格的metadata
。
答案 0 :(得分:3)
或者,如果您手动输入了DataTable,则可以执行以下操作:
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));
}
答案 1 :(得分:2)
也许你正在寻找这样的东西:
var query = new google.visualization.Query(DATA_SOURCE_URL);
query.setQuery('select dept, sum(salary) group by dept');
query.send(handleQueryResponse);
DATA_SOURCE_URL
可以对应Google图表数据源网址。
来自:https://developers.google.com/chart/interactive/docs/querylanguage