Advertisement
gersonab

hight

Aug 11th, 2011
273
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
jQuery 1.55 KB | None | 0 0
  1. <script type="text/javascript">
  2.             Highcharts.visualize = function(table, options) {
  3.                 // the categories
  4.                 options.xAxis.categories = [];
  5.                 $('tbody th', table).each( function(i) {
  6.                     options.xAxis.categories.push(this.innerHTML);
  7.                 });
  8.                
  9.                 // the data series
  10.                 options.series = [];
  11.                 $('tr', table).each( function(i) {
  12.                     var tr = this;
  13.                     $('th, td', tr).each( function(j) {
  14.                         if (j > 0) { // skip first column
  15.                             if (i == 0) { // get the name and init the series
  16.                                 options.series[j - 1] = {
  17.                                     name: this.innerHTML,
  18.                                     data: []
  19.                                 };
  20.                             } else { // add values
  21.                                 options.series[j - 1].data.push(parseFloat(this.innerHTML));
  22.                             }
  23.                         }
  24.                     });
  25.                 });
  26.                
  27.                 var chart = new Highcharts.Chart(options);
  28.             }
  29.                
  30.             // On document ready, call visualize on the datatable.
  31.             $(document).ready(function() {         
  32.                 var table = document.getElementById('datatable'),
  33.                 options = {
  34.                        chart: {
  35.                           renderTo: 'container',
  36.                           defaultSeriesType: 'column'
  37.                        },
  38.                        title: {
  39.                           text: 'Grafico de acompanhamento'
  40.                        },
  41.                        xAxis: {
  42.                        },
  43.                        yAxis: {
  44.                           title: {
  45.                              text: 'Vendas'
  46.                           }
  47.                        },
  48.                        tooltip: {
  49.                           formatter: function() {
  50.                              return '<b>'+ this.series.name +'</b><br/>'+
  51.                                 this.y +' '+ this.x.toLowerCase();
  52.                           }
  53.                        }
  54.                     };
  55.                
  56.                                    
  57.                 Highcharts.visualize(table, options);
  58.             });
  59.                
  60.         </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement