admin管理员组文章数量:1332404
The following is a table for the Google Charts API. I'm trying to sort the "Numbers" Column descending. Anyone know how to do this?
<script type="text/javascript" src=""></script>
<script type="text/javascript">
google.load('visualization', '1', {packages: ['table']});
</script>
<script type="text/javascript">
function drawVisualization() {
// Create and populate the data table.
var data = new google.visualization.DataTable();
data.addColumn('string', 'Names');
data.addColumn('number', 'Numbers');
data.addRows(3);
data.setCell(0, 0, 'Name 1');
data.setCell(1, 0, 'Name 2');
data.setCell(2, 0, 'Name 3');
data.setCell(0, 1, 1);
data.setCell(1, 1, 2);
data.setCell(2, 1, 3);
visualization = new google.visualization.Table(document.getElementById('table'));
visualization.draw(data, null);
}
google.setOnLoadCallback(drawVisualization);
</script>
<div id="table"></div>
The following is a table for the Google Charts API. I'm trying to sort the "Numbers" Column descending. Anyone know how to do this?
<script type="text/javascript" src="http://www.google./jsapi"></script>
<script type="text/javascript">
google.load('visualization', '1', {packages: ['table']});
</script>
<script type="text/javascript">
function drawVisualization() {
// Create and populate the data table.
var data = new google.visualization.DataTable();
data.addColumn('string', 'Names');
data.addColumn('number', 'Numbers');
data.addRows(3);
data.setCell(0, 0, 'Name 1');
data.setCell(1, 0, 'Name 2');
data.setCell(2, 0, 'Name 3');
data.setCell(0, 1, 1);
data.setCell(1, 1, 2);
data.setCell(2, 1, 3);
visualization = new google.visualization.Table(document.getElementById('table'));
visualization.draw(data, null);
}
google.setOnLoadCallback(drawVisualization);
</script>
<div id="table"></div>
Share
Improve this question
asked Mar 2, 2012 at 5:11
GeorgGeorg
6482 gold badges9 silver badges24 bronze badges
1
-
1
developers.google./chart/interactive/docs/gallery/table Search for event
sort
Look here for the playground code.google./apis/ajax/playground/… – Ron van der Heijden Commented May 22, 2012 at 11:12
1 Answer
Reset to default 6Yes. just add the following line below your data def., it will sort descending on number, and then ascendsing on name.
data.sort([{column: 1, desc:true}, {column: 0}]);
oh, you could also use this:
data.addRow(['Name 1',1]);
data.addRow(['Name 2',2]);
data.addRow(['Name 3',3]);
regards, Halma
本文标签: javascriptSort Column in TableGoogle Chart ToolsStack Overflow
版权声明:本文标题:javascript - Sort Column in Table - Google Chart Tools - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742279232a2445779.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论