forked from code-dot-org/code-dot-org
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunometerPercentagesByDay.js
More file actions
26 lines (23 loc) · 1.06 KB
/
funometerPercentagesByDay.js
File metadata and controls
26 lines (23 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
/* globals google */
// Creates and populates the chart-by-day DOM element with the data in percentagesByDay via a
// callback, after loading the Google Visualization API.
module.exports.drawChart = function drawChart(percentagesByDay) {
// Load the Visualization API and the appropriate packages, setting a callback
// to run when the API is loaded.
google.load('visualization', '1.0', {'packages':['corechart']});
google.setOnLoadCallback(function () {
drawChartCallback(percentagesByDay);
});
};
// The callback that creates and populates the data table, instantiates the
// chart, and draws it.
function drawChartCallback(percentagesByDay) {
var data = new google.visualization.DataTable();
data.addColumn('string', 'Date');
data.addColumn('number', 'Percentage');
data.addRows(percentagesByDay);
// Instantiate and draw our chart, passing in some options.
var options = {'title': 'Fun-O-Meter By Day', 'width': 800, 'height': 500};
var chart = new google.visualization.LineChart(document.getElementById('chart-by-day'));
chart.draw(data, options);
}