forked from zingchart-demos/node-express-couchdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
78 lines (74 loc) · 2.05 KB
/
index.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<!DOCTYPE html>
<html>
<head>
<title>CouchDB/Nano Demo</title>
<script type="text/javascript" src="./node_modules/zingchart/client/zingchart.min.js"></script>
</head>
<body>
<script>
// Generates GET requests to a URL.
function httpGet(Url){
var xmlHttp = new XMLHttpRequest();
xmlHttp.open("GET", Url, false);
xmlHttp.send(null);
return xmlHttp.responseText;
}
window.onload=function(){
// GET request to localhost:3000/test, which has been configured to send back our db data
var aData = JSON.parse(httpGet('http://localhost:3000/test'));
var seriesData = {
series_0: [],
series_1: [],
series_2: [],
series_3: []
};
// Push the data into the seriesData object's arrays.
for(var n = 0; n < aData['rows'].length; n++){
seriesData['series_0'].push(aData['rows'][n]['doc']['series0']);
seriesData['series_1'].push(aData['rows'][n]['doc']['series1']);
seriesData['series_2'].push(aData['rows'][n]['doc']['series2']);
seriesData['series_3'].push(aData['rows'][n]['doc']['series3']);
}
// Render the chart using the data from Mongo
zingchart.render({
id:"myChart",
width:"100%",
height:400,
data:{
"type":"line",
"title":{
"text":"Data Pulled from MongoDB"
},
"plot":{
"line-width":1,
"aspect":"spline",
"marker":{
"visible":false
}
},
"series":[
{
"values":seriesData['series_0']
},
{
"values":seriesData['series_1']
},
{
"values":seriesData['series_2']
},
{
"values":seriesData['series_3']
}
]
}
});
};
</script>
<div class="row">
<div class="small-12 columns">
<h1>CouchDB/Nano Demo</h1>
<div id="myChart"></div>
</div>
</div>
</body>
</html>