-
Notifications
You must be signed in to change notification settings - Fork 0
/
scriptPopACS.js
50 lines (42 loc) · 1.68 KB
/
scriptPopACS.js
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Load the Visualization API and chart packages
google.load('visualization', '1.0', {'packages':['corechart'], callback: drawPopACSChartFromCSV});
// Set a callback to run when the Google Visualization API is loaded.
google.setOnLoadCallback(drawPopACSChartFromCSV());
function drawPopACSChartFromCSV(){
// Get the csv file, and convert it into a string
$.get("csvFiles/AmericanCancerSocietyProgramPercentages.csv", function(csvString) {
// transform the CSV string into a 2D array
var arrayData = $.csv.toArrays(csvString, {onParseValue: $.csv.hooks.castToScalar});
// convert the 2D array into a data table google charts can read
var data = new google.visualization.arrayToDataTable(arrayData);
//console.log(data);
// var data = google.visualization.arrayToDataTable([
// ['Catagory', 'Percentage'],
// ['2004', 1000],
// ['2005', 1170],
// ['2006', 660],
// ['2007', 1030]
// ]);
//
// define chart options
var options = {
title: "American Cancer Society Program Expenses",
slices: {3: {offset: 0.2}
},
colors: ['blue', 'gray','red','black']
// width: 525,
// height: 375
// hAxis: {title: data.getColumnLabel(0), minValue: data.getColumnRange(0).min, maxValue: data.getColumnRange(1).max},
// vAxis: {title: data.getColumnLabel(1), minValue: data.getColumnRange(1).min, maxValue: 100},
// legend: 'none',
// trendlines: {
// 0:{
// color: 'green'
// }
// }
};
//draw the chart
var chart = new google.visualization.PieChart(document.getElementById('popupDivACS'));
chart.draw(data, options);
});
}