google.visualization.data.group 返回常规 DataTable 类
google.visualization.data.group
DataTable
使用 图表方法 getValue 获取组表中的值
getValue
getValue(rowIndex, colIndex)
帖子中的组表返回一行, 所以使用以下内容来了解价值......
groupView.getValue(0, 1)
请参阅以下工作代码段...
google.charts.load('current', { callback: drawChart, packages: ['gauge'] }); function drawChart() { //Create DataTable var data = new google.visualization.DataTable(); //Add Columns data.addColumn('string', 'CW'); data.addColumn('string', 'Business Division'); data.addColumn('string', 'Product'); data.addColumn('number', 'Cost'); data.addColumn('number', 'Quantity'); data.addColumn('number', 'Age (d)'); data.addColumn('string', 'Actual State'); //Add Rows var dataArray = []; //replaced with manual sample data for (i = 0; i < 5; i++) { dataArray.push([ 'CW' + i, 'GS', 'line' + i, 10, 99, 99, 'state' + i ]); } data.addRows(dataArray); //Create Data View var view = new google.visualization.DataView(data); view.setColumns([1, 3]); //Create Data Aggregation var groupView = google.visualization.data.group(view, [{ column: 0, type: 'string' }], [{ column: 1, aggregation: google.visualization.data.sum, type: 'number' }]); //Options var options = { max: groupView.getValue(0, 1) }; //Instantiate and draw chart, passing in options. var chart = new google.visualization.Gauge(document.getElementById('chart_div')); chart.draw(groupView, options); }
<script src="https://www.gstatic.com/charts/loader.js"></script> <div id="chart_div"></div>