Grouping & Ordering
  1. <html>
  2. <head>
  3. <script type="text/javascript" src="/JS"></script>
  4. <script type="text/javascript">
  5. ml.onload(function () {
  6.  
  7. var q = ml.query().from('maplarge/Donors').groupby('PartyCode');
  8. q.select('Amount').select('PartyCode').select('Amount.count').select('Amount.sum');
  9. q.select('Amount.avg').select('Amount.uniq');
  10. q.take('20').groupby('PartyCode').orderby('Amount.desc');
  11.  
  12. q.run(function (data, query) {
  13. var dataDiv = document.getElementById("dataDiv");
  14. dataDiv.innerHTML = ml.util.toJSON(data);
  15. });
  16. });
  17. </script>
  18. </head>
  19. <body>
  20. <div id="dataDiv">
  21.  
  22. </div>
  23. </body>
  24. </html>

Donations Totals by Day, groupby & orderby
  1. <html>
  2. <head>
  3. <script type="text/javascript" src="/JS"></script>
  4. <script type="text/javascript">
  5. ml.onload(function () {
  6.  
  7. var q = ml.query().from('maplarge/Donors');
  8. q.select('TimeStamp').select('Amount.count').select('Amount.sum');
  9. q.select('Amount.avg').take('760').groupby('TimeStamp').orderby('TimeStamp');
  10.  
  11. q.run(function (data, query) {
  12. var dataDiv = document.getElementById("dataDiv");
  13. dataDiv.innerHTML = ml.util.toJSON(data);
  14. });
  15. });
  16. </script>
  17. </head>
  18. <body>
  19. <div id="dataDiv">
  20. </div>
  21. </body>
  22. </html>

Donations by State, groupby & orderby

Ordering by Amount.desc means the Amount column will contains the highest single donation for that state.

  1. <html>
  2. <head>
  3. <script type="text/javascript" src="/JS"></script>
  4. <script type="text/javascript">
  5. ml.onload(function () {
  6.  
  7. var q = ml.query().from('Example/PoliticalDonations');
  8. q.select('State').select('Amount.count').select('Amount.sum');
  9. q.select('Amount').groupby('State').orderby('Amount.desc').take('100');
  10.  
  11. q.run(function(data){
  12. console.log(data);
  13.  
  14. //Show the data as an html table
  15. displayTable(document.getElementById("dataDiv"),data);
  16. });
  17.  
  18. });
  19. //Helper Function to Layout the Data
  20. function displayTable(dataDiv, data){
  21. var rows = ml.data.query.Query.transposeQueryData(data.data);
  22. console.log(rows);
  23. var head = [];
  24. ml.each(rows[0], function(k,v) {
  25. head.push(k);
  26. });
  27. rows.unshift(head);
  28. data=rows;
  29. var table = ml.$("<table/>").addClass('CSSTableGenerator');
  30. ml.$.each(data, function(rowIndex, r) {
  31. var row = ml.$("<tr/>");
  32. ml.$.each(r, function(colIndex, c) {
  33. var content = "<p>"+c+"</p>";
  34. row.append(ml.$("<t"+(rowIndex == 0 ? "h" : "d")+"/>").html(content));
  35. });
  36. table.append(row);
  37. });
  38.  
  39. ml.$(dataDiv).html(table);
  40. }
  41. </script>
  42. <style>
  43. table tr:nth-child(even) {
  44. background-color: #eee;
  45. }
  46. table tr:nth-child(odd) {
  47. background-color:#fff;
  48. }
  49. table th {
  50. background-color: black;
  51. color: white;
  52. padding: 4px;
  53. }
  54. table td {
  55. padding: 4px;
  56. }
  57. </style>
  58. </head>
  59. <body>
  60. <div id="dataDiv"></div>
  61. </body>
  62. </html>

Donations by Person, groupby
  1. <html>
  2. <head>
  3. <script type="text/javascript" src="/JS"></script>
  4. <script type="text/javascript">
  5. ml.onload(function () {
  6.  
  7. var q = ml.query().from('maplarge/Donors');
  8. q.select('Contrib').select('FecOccEmp').select('Amount.sum');
  9. q.select('Amount').groupby('Contrib').take('100');
  10.  
  11. q.run(function(data){
  12. console.log(data);
  13.  
  14. //Show the data as an html table
  15. displayTable(document.getElementById("dataDiv"),data);
  16. });
  17.  
  18. });
  19. //Helper Function to Layout the Data
  20. function displayTable(dataDiv, data){
  21. var rows = ml.data.query.Query.transposeQueryData(data.data);
  22. console.log(rows);
  23. var head = [];
  24. ml.each(rows[0], function(k,v) {
  25. head.push(k);
  26. });
  27. rows.unshift(head);
  28. data=rows;
  29. var table = ml.$("<table/>").addClass('CSSTableGenerator');
  30. ml.$.each(data, function(rowIndex, r) {
  31. var row = ml.$("<tr/>");
  32. ml.$.each(r, function(colIndex, c) {
  33. var content = "<p>"+c+"</p>";
  34. row.append(ml.$("<t"+(rowIndex == 0 ? "h" : "d")+"/>").html(content));
  35. });
  36. table.append(row);
  37. });
  38.  
  39. ml.$(dataDiv).html(table);
  40. }
  41. </script>
  42. <style>
  43. table tr:nth-child(even) {
  44. background-color: #eee;
  45. }
  46. table tr:nth-child(odd) {
  47. background-color:#fff;
  48. }
  49. table th {
  50. background-color: black;
  51. color: white;
  52. padding: 4px;
  53. }
  54. table td {
  55. padding: 4px;
  56. }
  57. </style>
  58. </head>
  59. <body>
  60. <div id="dataDiv"></div>
  61. </body>
  62. </html>

Donations by Occupations, groupby
  1. <html>
  2. <head>
  3. <script type="text/javascript" src="/JS"></script>
  4. <script type="text/javascript">
  5. ml.onload(function () {
  6.  
  7. var q = ml.query().from('maplarge/Donors');
  8. q.select('FecOccEmp').select('Amount.sum').select('Amount.count');
  9. q.groupby('FecOccEmp').take('100');
  10.  
  11. q.run(function(data){
  12. console.log(data);
  13.  
  14. //Show the data as an html table
  15. displayTable(document.getElementById("dataDiv"),data);
  16. });
  17.  
  18. });
  19. //Helper Function to Layout the Data
  20. function displayTable(dataDiv, data){
  21. var rows = ml.data.query.Query.transposeQueryData(data.data);
  22. console.log(rows);
  23. var head = [];
  24. ml.each(rows[0], function(k,v) {
  25. head.push(k);
  26. });
  27. rows.unshift(head);
  28. data=rows;
  29. var table = ml.$("<table/>").addClass('CSSTableGenerator');
  30. ml.$.each(data, function(rowIndex, r) {
  31. var row = ml.$("<tr/>");
  32. ml.$.each(r, function(colIndex, c) {
  33. var content = "<p>"+c+"</p>";
  34. row.append(ml.$("<t"+(rowIndex == 0 ? "h" : "d")+"/>").html(content));
  35. });
  36. table.append(row);
  37. });
  38.  
  39. ml.$(dataDiv).html(table);
  40. }
  41. </script>
  42. <style>
  43. table tr:nth-child(even) {
  44. background-color: #eee;
  45. }
  46. table tr:nth-child(odd) {
  47. background-color:#fff;
  48. }
  49. table th {
  50. background-color: black;
  51. color: white;
  52. padding: 4px;
  53. }
  54. table td {
  55. padding: 4px;
  56. }
  57. </style>
  58. </head>
  59. <body>
  60. <div id="dataDiv"></div>
  61. </body>
  62. </html>