I found a workaround using
(dataToAdd.K).map(function tmp(x) {return(x["c"])})
This gives you the array of rows in your dataToAdd
DataTable().
سؤال
I was trying to use the getRow() method (described here)
But when running my webpage I get "Uncaught TypeError: Object #<U> has no method 'getRow' "
.
Has this function been deprecated ? If not, how can I make sure I can use it ?
Here is my code :
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
google.load('visualization', '1',{'packages': ['table']});
and then later on (both data
and dataToAdd
are DataTable()
):
data.addRow(dataToAdd.getRow(0));
المحلول 2
I found a workaround using
(dataToAdd.K).map(function tmp(x) {return(x["c"])})
This gives you the array of rows in your dataToAdd
DataTable().
نصائح أخرى
If you read: https://developers.google.com/chart/interactive/docs/reference#google.visualization.arraytodatatable
You will find a function getValue(rowIndex, columnIndex)
In my example I have a list of lat/lons, of which I ensure are valid, then render. Upon clicking a lat/lon I want to do something with the lat/lons. Scroll down to the bottom to see the usage of DataTable.getValue()
var dataTable = new google.visualization.DataTable();
dataTable.addColumn('number', 'Latitude');
dataTable.addColumn('number', 'Longitude');
dataTable.addColumn('string', 'Name');
$.each(data, function(i, o) {
var lat = parseFloat(o.lat);
var lon = parseFloat(o.lon);
var name = o.name;
if(LIB.Location.isLatLonValid([lat, lon])) {
var row = [lat, lon, name];
dataTable.addRow(row);
}
});
var options = {
width : 550
,height : 240
,region: country
,legend: 'none'
,showTip : false
,mapType : 'normal'
};
var chart = new google.visualization.Map(document.getElementById('location_pin_chart'));
chart.draw(dataTable, options);
// handle clicking on pin
google.visualization.events.addListener(chart,'select', function(e) {
var selection = chart.getSelection();
var lat = dataTable.getValue(selection[0].row, 0); // HERE is where I get the value!
var lon = dataTable.getValue(selection[0].row, 1);
alert(lat + ", " + lon);
});
Capo answer is correct, still here is an similar way
dataToAdd.fg
This also gives direct access to the internal dataToAdd
DataTable() array