1
我使用Google图表创建新图表表格。我想得到明显的排名。例如:如何自定义Google图表
A:10 B:5 C:2 d:1
所以结果应显示这样的事情
d,C,B,A
是有没有办法做到这一点。 (我已经减去了值,但它不正确?
我使用Google图表创建新图表表格。我想得到明显的排名。例如:如何自定义Google图表
A:10 B:5 C:2 d:1
所以结果应显示这样的事情
d,C,B,A
是有没有办法做到这一点。 (我已经减去了值,但它不正确?
是的,这是可能的。
使用基本代码here作为基础:
var drawVisualizations = function() {
// Create and populate a data table.
var data = new google.visualization.DataTable();
data.addColumn('string', 'Force');
data.addColumn('number', 'Level');
// Add 2 rows.
// google.visualization.DataTable.addRows() can take a 2-dim array of values.
data.addRows([['Fire', 1], ['Water', 5]]);
// Add one more row.
data.addRow(['sand', 4]);
// Draw a table with this data table.
var originalVisualization = new google.visualization.Table(document.getElementById('original_data_table'));
originalVisualization.draw(data);
// Clone the data table and modify it a little.
var modifiedData = data.clone();
// Modify existing cell.
modifiedData.setCell(1, 1, 666);
// Sort the data by the 2nd column (counting from 0).
modifiedData.sort(1);
// Insert rows in the middle of the data table.
modifiedData.insertRows(2, [['new fire', 14], ['new water', 41]]);
// Draw a table with this data table.
var modifiedVisualization = new google.visualization.Table(document.getElementById('modified_data_table'));
modifiedVisualization.draw(modifiedData);
}
正如你可以看到,使用你的数据表中“排序()”将进行排序。有关排序命令的文档位于here
谢谢。我试过了,它不适用于BarChart。请访问以下网址https://code.google.com/apis/ajax/playground/?type=visualization#bar_chart – Mifas
这只是默认的条形图。你在那里对数据表进行了排序吗?如果是这样,你的代码是什么?简单地说它不起作用(当它在发布的例子中确实如此)并没有什么帮助。 – jmac
对不起,这是一个错误。我修改了代码。 http://pastebin.com/e7gDCnRR。请复制代码并粘贴到Google网页图表页面。 – Mifas