Created
October 4, 2012 16:28
-
-
Save mrnohr/3834777 to your computer and use it in GitHub Desktop.
Grails and Google Charts
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
<html> | |
<head> | |
<meta name="layout" content="main"> | |
<script type="text/javascript" src="https://www.google.com/jsapi"></script> | |
<script type="text/javascript"> | |
google.load("visualization", "1", {packages:["corechart"]}); | |
google.setOnLoadCallback(drawChart); | |
function drawChart() { | |
data = google.visualization.arrayToDataTable(${chartData}) | |
chart = new google.visualization.LineChart(document.getElementById('chart_div')); | |
chart.draw(data); | |
} | |
</script> | |
</head> | |
<body> | |
<div id="chart_div"></div> | |
</body> | |
</html> |
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
function drawChart() { | |
data = google.visualization.arrayToDataTable(${chartData}) | |
chart = new google.visualization.LineChart(document.getElementById('chart_div')); | |
options = { | |
colors: ${colors} | |
} | |
chart.draw(data, options); | |
} |
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
def chart() { | |
//create the data table (list of lists) - first row is the headers | |
def totalYardsStats = [["'Week'", "'Chicago'", "'Detroit'", "'Green Bay'", "'Minnesota'"]] | |
//actual data CHI DET GB MIN | |
totalYardsStats << ["'Week 1'", 428, 429, 324, 389] | |
totalYardsStats << ["'Week 2'", 168, 296, 321, 327] | |
totalYardsStats << ["'Week 3'", 274, 437, 268, 344] | |
totalYardsStats << ["'Week 4'", 430, 341, 421, 227] | |
[chartData: totalYardsStats] | |
} |
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
def chart() { | |
def totalYardsStats = ... //as before | |
//make the colors match team colors | |
def colors = [ | |
"'#FF8000'", //orange - Chicago | |
"'#0040FF'", //blue - Detroit | |
"'#21610B'", //green - Green Bay | |
"'#6A0888'" //purple - Minnesota | |
] | |
[chartData: totalYardsStats, colors:colors] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment