Updating Data in Google Visualization DataTable

本小妞迷上赌 提交于 2019-12-06 13:30:52
HansMaulwurf

As Bob is the first row you inserted, his occupation resides in row with index 0 and column with index 1:

data.setValue(0, 1, 'Beach Comber');

In case you don't know the row index of a person who's occupation is to be updated, I suggest iterating or filtering to find all Bob rows (or the one Bob row in your case). Iteration is the 'brute force' way and goes like this

for (var y = 0, maxrows = data.getNumberOfRows(); y < maxrows; y++) {
    if (data.getValue(y, 0) == 'Bob') {
        data.setValue(y, 1, 'Beach Comber');
    }
}

Filtering is more elegant:

var foundRows = data.getFilteredRows([{column: 0, value: 'Bob'}]);
for (var y = 0, maxrows = foundRows.length; y < maxrows; y++) {
     data.setValue(foundRows[y], 1, 'Beach Comber');
}

The reference API-Doc can be found here: https://developers.google.com/chart/interactive/docs/reference#DataTable and holds a bunch a good examples.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!