jgtable.js 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*
  2. *
  3. * jQuery Google Charts - Table Plugin 0.9
  4. *
  5. * $Date: 2009/10/01 18:28:41 $
  6. * $Rev:171 $
  7. *
  8. * @requires
  9. * jGCharts Base
  10. * Metadata
  11. *
  12. * Copyright (c) 2008 Massimiliano Balestrieri
  13. * Examples and docs at: http://maxb.net/blog/
  14. * Licensed GPL licenses:
  15. * http://www.gnu.org/licenses/gpl.html
  16. *
  17. */
  18. if(!window.jGCharts)
  19. alert("Include jGCharts Base Plugin");
  20. jGCharts.Table = {
  21. init : function(options){
  22. return this.each(function(nr, el){
  23. var that = this;
  24. var _table = jQuery(that).find("table").eq(0);
  25. var _options = jQuery.extend({
  26. single : 'metadata'
  27. }, options);
  28. if(!_options.target){
  29. var _target = jQuery('<div class="jgchart">');
  30. jQuery(that).prepend(_target);
  31. }else{
  32. var _target = jQuery(_options.target);
  33. }
  34. _options = jQuery.extend(jQuery(that).metadata({cre: /({[\s\S]*})/, single : _options.single.toString()}), _options);
  35. //console.log(_options);
  36. if(!_options.data){
  37. _options.data = [];
  38. for(var x= 0;x< jQuery(that).find("tbody > tr").size();x++){
  39. _options.data.push(
  40. jQuery.map( jQuery(that).find("tbody > tr:eq(" + x + ") > td"),
  41. function(td,index){
  42. //if(index % 11 == 1 || index % 11 == 2){
  43. if(parseFloat(jQuery(td).text()))
  44. return parseFloat(jQuery(td).text());
  45. else
  46. return 0;
  47. //}
  48. }
  49. )
  50. );
  51. }
  52. }
  53. //console.log(_options.data);
  54. if(!_options.axis_labels)
  55. _options.axis_labels = jQuery.map( jQuery(that).find("tbody > tr > th.serie"),
  56. function(th) { return jQuery(th).text(); }
  57. );
  58. if(!_options.legend)
  59. _options.legend = jQuery.map( jQuery(that).find("thead > tr:last > th.serie"),
  60. function(th) { return jQuery(th).text(); }
  61. );
  62. var api = new jGCharts.Api();
  63. var url = api.make(_options);
  64. var ch = jQuery('<img>')
  65. .attr('src', url);
  66. if(_options.gui){
  67. ch.addClass("jggui");
  68. }
  69. _target
  70. .append(ch);
  71. });
  72. }
  73. };
  74. jQuery.fn.jgtable = jGCharts.Table.init;