<html> <head> <script type="text/javascript" src="/JS"></script> <script type="text/javascript"> ml.onload(function () { var q = ml.query().from('maplarge/Donors').groupby('PartyCode'); q.select('Amount').select('PartyCode').select('Amount.count').select('Amount.sum'); q.select('Amount.avg').select('Amount.uniq'); q.take('20').groupby('PartyCode').orderby('Amount.desc'); q.run(function (data, query) { var dataDiv = document.getElementById("dataDiv"); dataDiv.innerHTML = ml.util.toJSON(data); }); }); </script> </head> <body> <div id="dataDiv"> </div> </body> </html>
<html> <head> <script type="text/javascript" src="/JS"></script> <script type="text/javascript"> ml.onload(function () { var q = ml.query().from('maplarge/Donors'); q.select('TimeStamp').select('Amount.count').select('Amount.sum'); q.select('Amount.avg').take('760').groupby('TimeStamp').orderby('TimeStamp'); q.run(function (data, query) { var dataDiv = document.getElementById("dataDiv"); dataDiv.innerHTML = ml.util.toJSON(data); }); }); </script> </head> <body> <div id="dataDiv"> </div> </body> </html>
Ordering by Amount.desc means the Amount column will contains the highest single donation for that state.
<html> <head> <script type="text/javascript" src="/JS"></script> <script type="text/javascript"> ml.onload(function () { var q = ml.query().from('Example/PoliticalDonations'); q.select('State').select('Amount.count').select('Amount.sum'); q.select('Amount').groupby('State').orderby('Amount.desc').take('100'); q.run(function(data){ console.log(data); //Show the data as an html table displayTable(document.getElementById("dataDiv"),data); }); }); //Helper Function to Layout the Data function displayTable(dataDiv, data){ var rows = ml.data.query.Query.transposeQueryData(data.data); console.log(rows); var head = []; ml.each(rows[0], function(k,v) { head.push(k); }); rows.unshift(head); data=rows; var table = ml.$("<table/>").addClass('CSSTableGenerator'); ml.$.each(data, function(rowIndex, r) { var row = ml.$("<tr/>"); ml.$.each(r, function(colIndex, c) { var content = "<p>"+c+"</p>"; row.append(ml.$("<t"+(rowIndex == 0 ? "h" : "d")+"/>").html(content)); }); table.append(row); }); ml.$(dataDiv).html(table); } </script> <style> table tr:nth-child(even) { background-color: #eee; } table tr:nth-child(odd) { background-color:#fff; } table th { background-color: black; color: white; padding: 4px; } table td { padding: 4px; } </style> </head> <body> <div id="dataDiv"></div> </body> </html>
<html> <head> <script type="text/javascript" src="/JS"></script> <script type="text/javascript"> ml.onload(function () { var q = ml.query().from('maplarge/Donors'); q.select('Contrib').select('FecOccEmp').select('Amount.sum'); q.select('Amount').groupby('Contrib').take('100'); q.run(function(data){ console.log(data); //Show the data as an html table displayTable(document.getElementById("dataDiv"),data); }); }); //Helper Function to Layout the Data function displayTable(dataDiv, data){ var rows = ml.data.query.Query.transposeQueryData(data.data); console.log(rows); var head = []; ml.each(rows[0], function(k,v) { head.push(k); }); rows.unshift(head); data=rows; var table = ml.$("<table/>").addClass('CSSTableGenerator'); ml.$.each(data, function(rowIndex, r) { var row = ml.$("<tr/>"); ml.$.each(r, function(colIndex, c) { var content = "<p>"+c+"</p>"; row.append(ml.$("<t"+(rowIndex == 0 ? "h" : "d")+"/>").html(content)); }); table.append(row); }); ml.$(dataDiv).html(table); } </script> <style> table tr:nth-child(even) { background-color: #eee; } table tr:nth-child(odd) { background-color:#fff; } table th { background-color: black; color: white; padding: 4px; } table td { padding: 4px; } </style> </head> <body> <div id="dataDiv"></div> </body> </html>
<html> <head> <script type="text/javascript" src="/JS"></script> <script type="text/javascript"> ml.onload(function () { var q = ml.query().from('maplarge/Donors'); q.select('FecOccEmp').select('Amount.sum').select('Amount.count'); q.groupby('FecOccEmp').take('100'); q.run(function(data){ console.log(data); //Show the data as an html table displayTable(document.getElementById("dataDiv"),data); }); }); //Helper Function to Layout the Data function displayTable(dataDiv, data){ var rows = ml.data.query.Query.transposeQueryData(data.data); console.log(rows); var head = []; ml.each(rows[0], function(k,v) { head.push(k); }); rows.unshift(head); data=rows; var table = ml.$("<table/>").addClass('CSSTableGenerator'); ml.$.each(data, function(rowIndex, r) { var row = ml.$("<tr/>"); ml.$.each(r, function(colIndex, c) { var content = "<p>"+c+"</p>"; row.append(ml.$("<t"+(rowIndex == 0 ? "h" : "d")+"/>").html(content)); }); table.append(row); }); ml.$(dataDiv).html(table); } </script> <style> table tr:nth-child(even) { background-color: #eee; } table tr:nth-child(odd) { background-color:#fff; } table th { background-color: black; color: white; padding: 4px; } table td { padding: 4px; } </style> </head> <body> <div id="dataDiv"></div> </body> </html>