SHARE
TWEET

Untitled

a guest Feb 19th, 2019 72 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var data = google.visualization.arrayToDataTable([
  2.       ['Year', 'Sales', 'Expenses'],
  3.       ['2004',  1000,      400],
  4.       ['2005',  1170,      460],
  5.       ['2006',  660,       1120],
  6.       ['2007',  1030,      540]
  7.     ]);
  8.    
  9. var data = new google.visualization.DataTable();
  10. data.addColumn('string', 'Year');
  11. data.addColumn('number', 'Sales');
  12. data.addColumn('number', 'Expenses');
  13. data.addRows([  ['2004', 1000 , 400], ['2005', 1170, 460], ['2006', 660, 1120], ['2007',1030,540]
  14.   ]);
  15.    
  16. ['Year', 'Sales', 'Expenses' , 'Other'],
  17. ['2004',  1000,      400     ,  232   ],
  18. ['2005',  1170,      460    ,  421   ],
  19. ['2006',  660,       1120    ,  4324  ],
  20. ['2007',  1030,      540     ,  4234  ],
  21. ['2008',  1530,      50     ,    234  ],
  22.    
  23. // function to update the chart with new data.
  24.       function updateChart() {
  25.  
  26.           dataTable = new google.visualization.DataTable();
  27.  
  28.           var newData = [['Year', 'Sales', 'Expenses' , 'Other'],
  29.             ['2004',  1000,      400     ,  232   ],
  30.             ['2005',  1170,      460    ,  421   ],
  31.             ['2006',  660,       1120    ,  4324  ],
  32.             ['2007',  1030,      540     ,  4234  ],
  33.             ['2008',  1530,      50     ,    234  ]];
  34.  
  35.           // determine the number of rows and columns.
  36.           var numRows = newData.length;
  37.           var numCols = newData[0].length;
  38.  
  39.           // in this case the first column is of type 'string'.
  40.           dataTable.addColumn('string', newData[0][0]);
  41.  
  42.           // all other columns are of type 'number'.
  43.           for (var i = 1; i < numCols; i++)
  44.             dataTable.addColumn('number', newData[0][i]);          
  45.  
  46.           // now add the rows.
  47.           for (var i = 1; i < numRows; i++)
  48.             dataTable.addRow(newData[i]);            
  49.  
  50.           // redraw the chart.
  51.           chart.draw(dataTable, options);        
  52.  
  53.       }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top