Created
September 4, 2014 05:16
-
-
Save grumpit/364c42b08da6695cd404 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@paper_totals_by_client = Paper.past_pending | |
.joins(:client) | |
.group("clients.name") | |
.limit(5) | |
.count | |
# returns an object like the following: | |
# => {"Sample Business"=>1, "Sample Business 2"=>1, "Sample Business 3"=>1, "Sample Business 4"=>6} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script type="text/javascript" src="https://www.google.com/jsapi"></script> | |
<script type="text/javascript"> | |
google.load('visualization', '1.1', {packages: ['corechart', 'timeline']}); | |
google.setOnLoadCallback(drawChart); | |
function drawChart() { | |
var clientPaperCountChart, clientPaperCounts, clientPaperCountData, clientPaperCountOptions; | |
clientPaperCounts = $.parseJSON("<%= j raw @paper_totals_by_client.to_a.to_json %>"); | |
clientPaperCounts.forEach(function(element, index, array) { | |
array[index].push('color: #3b8eb4; opacity: 0.5'); | |
}); | |
clientPaperCounts.unshift(['Client Name', 'Papers', {role: 'style'}]); | |
clientPaperCountData = google.visualization.arrayToDataTable(clientPaperCounts); | |
clientPaperCountOptions = { | |
title: "Papers by Client (Top <%= j @paper_totals_by_client.length.to_s %>)", | |
width: 400, | |
height: 300, | |
legend: { position: "none" } | |
}; | |
clientPaperCountChart = new google.visualization.BarChart(document.getElementById('client_paper_count_chart')); | |
clientPaperCountChart.draw(clientPaperCountData, clientPaperCountOptions); | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment