-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWHMTopicsChart.html
More file actions
220 lines (139 loc) · 6.42 KB
/
WHMTopicsChart.html
File metadata and controls
220 lines (139 loc) · 6.42 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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
<html>
<head>
<!-- Data visualization produced by Daniel Johnson ( http://orcid.org/0000-0003-1976-0635 ) in the CDS of the Hesburgh Library, University of Notre Dame, December 2017. Based on data generated by English graduate students, especially Anton Povzner and his team. This visualization is free for use, but is not the work of professional programmers and is not warranted in any way; use at your own risk -->
<title>Western Home Monthly Topic Models</title>
<!--Load the AJAX API-->
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript">
// Load the Visualization API and the corechart package.
google.charts.load('current', {'packages':['corechart', 'controls']});
// Set a callback to run when the Google Visualization API is loaded.
google.charts.setOnLoadCallback(drawChart);
var chart;
var chartOptions = {};
var columns = [];
var series = {};
var view;
// Callback that creates and populates a data table,
// instantiates the pie chart, passes in the data and
// draws it.
function drawChart() {
// Create the data table.
// var data = new google.visualization.DataTable();
var query = new google.visualization.Query('https://docs.google.com/spreadsheets/d/1LsIJVj4iC9IC56vc9d4D81hi3XrHh0M_KRVzDIKCA-A/gviz/tq?range=A1:AO33');
// query.setQuery('select A, sum(B) group by B');
var test = 'test'
var myData = query.send(handleQueryResponse);
function handleQueryResponse(response) {
if (response.isError()) {
alert('Error in query: ' + response.getMessage() + ' ' + response.getDetailedMessage());
return;
}
// Get our dataset
dataset = response.getDataTable();
// Set chart options
chartOptions = {
//legend: { position: 'top', alignment: 'end' }
'title':'WHM Visualized',
'width':1340,
'height':680,
chartArea:{
//left:10,
//right:10, // !!! works !!!
//bottom:20, // !!! works !!!
//top:20,
top:"25%",
width:"78%",
height:"65%"
},
series: series,
legend: { position: 'top', maxLines: 6,
textStyle: {fontSize: 15} },
hAxis: {
title: 'Year',
//Removes comma
format: '0'
},
vAxis: {
title: 'Topic Proportion',
//scaleType: 'log',
ticks: [0, .02, .04, .06, .08, .1, .12],
format: 'percent'
}
};
chart = new google.visualization.LineChart(document.getElementById('chart_div'));
//chart.draw(dataset, {width: 600, height: 440, title:'test'});
chart.draw(dataset, chartOptions);
// Some code adapted from http://jsfiddle.net/xDUPF/53/
for (var i = 0; i < dataset.getNumberOfColumns(); i++) {
columns.push(i);
if (i > 0) {
series[i - 1] = {};
}
}
// Add a listener for user clicks
google.visualization.events.addListener(chart, 'select', function () {
var selectedItem = chart.getSelection();
// This loop code adapted from: http://jsfiddle.net/xDUPF/53/
if (selectedItem.length > 0) {
// if row is undefined, we clicked on the legend
if (selectedItem[0].row === null) {
var col = selectedItem[0].column;
if (columns[col] == col) {
// hide the data series
columns[col] = {
label: dataset.getColumnLabel(col),
type: dataset.getColumnType(col),
calc: function () {
return null;
}
};
// grey out the legend entry
series[col - 1].color = '#CCCCCC';
}
else {
// show the data series
columns[col] = col;
series[col - 1].color = null;
//alert(columns[col] + " " + col);
}
view = new google.visualization.DataView(dataset);
view.setColumns(columns);
chart.draw(view, chartOptions);
}
}
});
} // End of handleQueryResponse
} // End of drawChart
function deselectAll (){
for (var j = 0; j < (dataset.getNumberOfColumns() - 1); j++) {
//BUT THIS WORKS!:
columns[j+1] = {
//columns[j] = {
label: dataset.getColumnLabel(j+1),
type: dataset.getColumnType(j+1),
calc: function () {
return null;
}
};
// grey out the legend entry
series[j].color = '#CCCCCC';
}
view = new google.visualization.DataView(dataset);
view.setColumns(columns);
chart.draw(view, chartOptions);
//columns = newColumns;
//series = newSeries;
} // End of deselectAll
</script>
</head>
<body>
<div>
<div id="chart_div"></div>
<div style="text-align: center;"><input type="button" Value="Clear All" onclick="deselectAll()" style="width:120px;height:70px;font-size:22px; "></div>
</div>
<div>
<span style="text-size:small">For more information, <a href="index.html">visit project information page here</a>.</span>
</div>
</body>
</html>