Reputation: 309
the td id='data' has the value below
['car', 7],['jeep', 2],['taxi', 1]
I want to get the value of 'td tag' and put on "Google Chart" arrayToDataTable
i tried this but not working
var x = document.getElementById('data').innerHTML; var data = google.visualization.arrayToDataTable([ ['Data', 'Value'], x
]);
Can anyone tell me how to do it.... need help
Upvotes: 1
Views: 991
Reputation: 196
you need to add brackets and make an array out of the string (innerHTML / innerTEXT) that you get from the TD and then add those rows.
Be sure the TD is inside TR and that is inside TABLE, or use a DIV instead of a TD
var data = new google.visualization.DataTable();
data.addColumn('string', 'Cartype');
data.addColumn('number', 'Amount');
//var tdString = "['car', 7],['jeep', 2],['taxi', 1]";
//var tdString = document.getElementById('data').textContent;
var tdString = document.getElementById('data').innerHTML;
var arr = eval("[" + tdString + "]");
data.addRows(arr);
Anyway: working fiddle here : https://jsfiddle.net/L3tNE/15/
Upvotes: 3