javascript - How to write a custom formatter for Google DataTables (for use on visualisation api) -
I am looking to format my data in which I change the numbers with the mouse.
As far as I can tell that Google does not currently have the format to do this:
A brief mention in the documentation about custom formats But I can not find any such document
Can anyone tell me in the right direction?
There is a similar question on stack overflow:. However, the question was used only by using the built-in formats (which I think that I can not do). I do not think make you able to do the current format as you wish You can, but you will be able to make your own format easily enough. I put the iconFormatter together for a sample - it can be adjusted to whatever you need, to do it. Hope that helps.
& lt; Html xmlns = "http://www.w3.org/1999/xhtml" & gt; & Lt; Top & gt; & Lt; Script type = "text / javascript" src = "http://www.google.com/jsapi" & gt; & Lt; / Script & gt; & Lt; Script type = "text / javascript" & gt; Google.load ('Visualization', '1', {packages: ['table']}); & Lt; / Script & gt; & Lt; Script type = "text / javascript" & gt; / ** * Givis icon format * @PRAM {Object & lt; Number, string & gt;} icon URI * / var iconFormatter = map for maps (mapMap) {this.iconMap = iconMap; } / ** * To formattify a gviz datatyal column * @the ultimate {object} DT Datatable * @param {number} column index number * / iconFormatter.prototype.format = function (dt, column) {for (var i = 0; I & lt; dt.getNumberOfRows (); i ++) {var formatted value = this.iconMap [dt.getValue (i, column)]; Var html string = "& lt; img src =" + valued value "/>"; Dt.setFormattedValue (i, column, html string); // built-in value consol.log protected (dt.getValue (i, column)); }} & Lt; / Script & gt; & Lt; Script & gt; Function drawVisualization () {// Create and populate data table. Var data = new google.visualization.DataTable (); Data.addColumn ('string', 'name'); Data.addColumn ('number', 'height'); Data.addRows (3); Data.setCell (0, 0, 'Tong Anne Mu'); Data.setCell (1, 0, 'Huang ange fa'); Data.setCell (2, 0, 'Teng NU'); Data.setCell (0, 1, 174); Data.setCell (1, 1, 523); Data.setCell (2, 1, 86); Var iconmap = {174: "http://farm1.static.flickr.com/76/buddyicons/63892905@N00.jpg?1149480603", 523: "http://farm1.static.flickr.com/28/buddyicons /20741728@N00.jpg?1129271399 ", 86:" http://farm3.static.flickr.com/2698/buddyicons/70986564@N00.jpg?1303489082 "// other numbers} // Create and draw visualization. Visualization = new google.visualization.Table (document.getElementById ('table')); // apply to our format, such as normal var format = new iconformer (iconmap); Formatter.format (data, 1); // Allow html, like any html formatter will require visualization.draw (data, {allowHtml: true}); } Google.setOnLoad callback (draft); & Lt; / Script & gt; & Lt; / Head & gt; & Lt; Body & gt; & Lt; Div id = "table" & gt; & Lt; / Div & gt; & Lt; / Body & gt; & Lt; / Html & gt;
Comments
Post a Comment