How To Change The Format In The Datatable's Google Chart Api With Javascript
I would like to change the format of the data in the DataTable in order to make it more flexible and the Chart is still the same with the first one. Default: ['Year', 'Sales', 'E
Solution 1:
You must transpose array like: http://jsfiddle.net/krzysztof_safjanowski/Mw398/1/
var data = google.visualization.arrayToDataTable(transposeArray([
['Year', '2004', '2005', '2006', '2007'],
['Sales', 1000, 1170, 660, 1030],
['Expenses', 400, 460, 1120, 540]
]));
functiontransposeArray(array) {
returnarray[0].map(function (col, i) {
returnarray.map(function (row) {
return row[i];
});
});
}
Before pass data to arrayToDataTable
you mast prepare it in format that google charts will understand.
Transpose – http://en.wikipedia.org/wiki/Transpose
Method map
– https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map
Post a Comment for "How To Change The Format In The Datatable's Google Chart Api With Javascript"