-
Notifications
You must be signed in to change notification settings - Fork 0
/
chart.html
59 lines (52 loc) · 1.9 KB
/
chart.html
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
<html>
<head>
<script src="jquery.csv.js"></script>
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript">
google.charts.load('current', { 'packages': ['corechart'] });
google.charts.setOnLoadCallback(drawChart);
function drawChart() {
var queryOptions = {
csvColumns: ['date', 'number'],
csvHasHeader: false
}
var csvUrl = 'data.csv'
var query = new google.visualization.Query(csvUrl, queryOptions);
query.send(handleQueryResponse);
function handleQueryResponse(response) {
if (response.isError()) {
alert('Error in query: ' + response.getMessage() + ' ' + response.getDetailedMessage());
return;
}
var options = {
title: 'Stargazers Over Time',
curveType: 'function',
legend: { position: 'none' },
width: 800
};
var data = response.getDataTable();
var getKeys = function (data) {
var keys = [];
for (var key in data) {
keys.push(key);
}
return keys;
alert(keys);
}
//alert(data.getColumnLabel(0));
var chart = new google.visualization.LineChart(document.getElementById('curve_chart'));
google.visualization.events.addListener(chart, 'ready', function () {
curve_chart.innerHTML = '<img id="chart" src="' + chart.getImageURI() + '">';
document.getElementById("download_link").setAttribute("href", chart.getImageURI())
document.getElementById("download_link").click();
});
chart.draw(data, options);
}
}
</script>
</head>
<body>
<div id="curve_chart" style="width: 900px; height: 500px"></div>
<a style="display:none" id="download_link" href="/" download>download</a>
</body>
</html>