jquery.gvChart-1.0.1.min.js 2.1 KB

12345678910111213141516
  1. /*
  2. * jQuery gvChart plugin
  3. * This plugin was created to simplify things when using Google Visualisation Charts.
  4. * It still needs to be used with google script import tag, however now you can
  5. * crate chart from your table.
  6. * All examples you will find on http://www.ivellios.toron.pl/technikalia/demos/gvChart/
  7. * @name jquery.gvChart-1.0.1.min.js
  8. * @author Janusz Kamieński - http://www.ivellios.toron.pl/technikalia
  9. * @version 1.0.1
  10. * @date December 04, 2010
  11. * @category jQuery plugin google charts
  12. * @copyright (c) 2010 Janusz Kamieński (www.ivellios.toron.pl)
  13. * @license CC Attribution Works 3.0 Poland - http://creativecommons.org/licenses/by/3.0/pl/deed.en_US
  14. * @example Visit http://www.ivellios.toron.pl/technikalia/demos/gvChart/ for more informations about this jQuery plugin
  15. */
  16. (function(jQuery){jQuery.fn.gvChart=function(settings){defaults={hideTable:true,chartType:'AreaChart',chartDivID:'gvChartDiv',gvSettings:null};var el=document.createElement('div');jQuery(el).insertBefore(this);gvChartCount++;gvChartID=defaults.chartDivID+gvChartCount;jQuery(el).attr('id',gvChartID);jQuery(el).addClass('gvChart');if(settings){jQuery.extend(defaults,settings);}if(defaults.hideTable)$(this).hide();var data=new google.visualization.DataTable();data.addColumn('string','X labels');var a=new Array();var headers=$(this).find('thead').find('th');var rows=$(this).find('tbody').find('tr');rows.each(function(index){data.addColumn('number',$(this).find('th').text());});data.addRows(headers.length-1);headers.each(function(index){if(index){data.setCell(index-1,0,$(this).text());}});rows.each(function(index){$(this).find('td').each(function(index2){data.setCell(index2,index+1,parseFloat($(this).text()));});});chartSettings={title:$(this).find('caption').text()};if(defaults.gvSettings){jQuery.extend(chartSettings,defaults.gvSettings);}eval("var chart = new google.visualization."+defaults.chartType+"(document.getElementById('"+gvChartID+"'))");chart.draw(data,chartSettings);}})(jQuery);function gvChartInit(){gvChartCount=0;google.load('visualization','1',{packages:['corechart']});}