Skip to content

Commit

Permalink
Issue #10 -Added language chart to dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
wdroste committed Dec 11, 2013
1 parent 58ca50c commit 7e4ac74
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 22 deletions.
20 changes: 20 additions & 0 deletions grails-app/controllers/org/sacredheart/DashboardController.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.sacredheart

import grails.converters.JSON

/**
* Dashboard data controller.
*/
class DashboardController {

/**
* Get the language data for all the patients.
*/
def languageData() {
render Patient.LANGUAGE.collect { lang ->
def count = Patient.countByLanguage(lang)
def display = message(code:"patient.language.select.${lang}")
[display, count]
} as JSON
}
}
39 changes: 17 additions & 22 deletions grails-app/views/index.gsp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
<div id="race_chart"></div>
</div>
<div class="span6">
<div id="veteran_chart"></div>
<div id="language_chart"></div>
</div>
</div>
<!--Load the AJAX API-->
Expand All @@ -88,27 +88,7 @@
genderChart();
citizenChart();
raceChart();
veteranChart();
}

function veteranChart() {
// Create the data table.
var data = new google.visualization.DataTable();
data.addColumn('string', 'Population of Veterans');
data.addColumn('number', '#');
data.addRows([
['Veteran', ${Patient.countByVeteran(YesNo.Yes)}],
['Civilian', ${Patient.countByVeteran(YesNo.No)}]
]);

// Set chart options
var options = {'title':'Population of Veterans',
'width':400,
'height':300};

// Instantiate and draw our chart, passing in some options.
var chart = new google.visualization.PieChart(document.getElementById('veteran_chart'));
chart.draw(data, options);
languageChart();
}

function raceChart() {
Expand Down Expand Up @@ -174,6 +154,21 @@
var chart = new google.visualization.PieChart(document.getElementById('gender_chart'));
chart.draw(data, options);
}

function languageChart() {
// Create the data table.
var data = new google.visualization.DataTable();
data.addColumn('string', 'Language');
data.addColumn('number', '#');
data.addRows(${g.include(controller:'dashboard', action:'languageData')});

// Set chart options
var options = {'title':'Language', 'width':400, 'height':300};

// Instantiate and draw our chart, passing in some options.
var chart = new google.visualization.PieChart(document.getElementById('language_chart'));
chart.draw(data, options);
}
</r:script>
</shiro:authenticated>

Expand Down

0 comments on commit 7e4ac74

Please sign in to comment.