1 | function GetData()
|
---|
2 | {
|
---|
3 | //calls the xml request in a loop based on the current sources
|
---|
4 | var source = ['Mrk 421','Mrk 501'];
|
---|
5 | for (i = 0; i<source.length; i++)
|
---|
6 | {
|
---|
7 | // alert (source[i]);
|
---|
8 | GetXMLData(i, source);
|
---|
9 |
|
---|
10 | //$('#data').append('1st'+source);
|
---|
11 | }
|
---|
12 | }
|
---|
13 | /*function getDate(day){
|
---|
14 |
|
---|
15 | var days = day;
|
---|
16 | return days;
|
---|
17 | }*/
|
---|
18 |
|
---|
19 | function GetXMLData(index, source)
|
---|
20 | {
|
---|
21 | // alert("test XML Data");
|
---|
22 | var XML;
|
---|
23 | //$('#data').append(' xmlData pass'+source+" "+index);
|
---|
24 | XML = new XMLHttpRequest();
|
---|
25 | //NOTE: previous errors on the request was caused by appending "http://www.fact-project.org"
|
---|
26 | XML.open("GET","/smartfact/index.php?source="+escape(source[index])+"&time="+year+"-"+month+"-"+day,true);
|
---|
27 | dataSource = new Array();
|
---|
28 | XML.onload=function()
|
---|
29 | {
|
---|
30 | if (XML.status==200)
|
---|
31 | {
|
---|
32 | //alert("request ok");
|
---|
33 | line=XML.responseText.split('\n');
|
---|
34 | dataSource.push(line);
|
---|
35 | if (dataSource.length == source.length)
|
---|
36 | {
|
---|
37 | // alert("new datasource");
|
---|
38 | displayXMLData(dataSource, source); //this will be called when the last data from the list is read
|
---|
39 | //$('#data').append('successfully load'+source +""+dataSource);
|
---|
40 |
|
---|
41 | }
|
---|
42 | }
|
---|
43 | else
|
---|
44 | alert("status is " + XML.status);
|
---|
45 | };
|
---|
46 |
|
---|
47 | XML.send();
|
---|
48 | }
|
---|
49 |
|
---|
50 | function displayXMLData(dataSource, source)
|
---|
51 | {
|
---|
52 | var options =
|
---|
53 | {
|
---|
54 | chart: {
|
---|
55 | renderTo: 'Graph' /* display to div Graph*/
|
---|
56 |
|
---|
57 | },
|
---|
58 |
|
---|
59 | xAxis: {
|
---|
60 | categories:[]
|
---|
61 | },
|
---|
62 | series:[], /* array of Data */
|
---|
63 |
|
---|
64 | remove:function()
|
---|
65 | {
|
---|
66 | return false;
|
---|
67 | },
|
---|
68 |
|
---|
69 | exporting: { /*--------------------*/
|
---|
70 | buttons: { /* */
|
---|
71 | exportButton: { /* Export */
|
---|
72 | menuItems: null, /* to */
|
---|
73 | onclick: function() { /* PNG.file */
|
---|
74 | this.exportChart(); /*--------------------*/
|
---|
75 | }
|
---|
76 | }
|
---|
77 | }
|
---|
78 | },
|
---|
79 | plotOptions : {
|
---|
80 |
|
---|
81 | series : {
|
---|
82 | lineWidth: 3,
|
---|
83 |
|
---|
84 | marker : {
|
---|
85 | enabled:false
|
---|
86 | }
|
---|
87 | }
|
---|
88 | }
|
---|
89 | };
|
---|
90 | //This function splits the lines of data per data source
|
---|
91 | var dataGraph = new Array(source.length);
|
---|
92 | var Time = new Array(source.length);
|
---|
93 | var Temp = new Array();
|
---|
94 | var Hour = new Array();
|
---|
95 | var Min = new Array();
|
---|
96 | var HourMin=new Array();
|
---|
97 | var chart = new Highcharts.Chart(options);
|
---|
98 | for (i=0; i<source.length; i++)
|
---|
99 | {
|
---|
100 | dataGraph[i] = new Array(); //dataGraph contains the individual points for each source i
|
---|
101 | Time[i] = new Array(); // Time contains the individual time for each sources.
|
---|
102 | chart.addSeries({name:source[i], data:[]}); // created a series of data and add name of displayed source
|
---|
103 |
|
---|
104 | for(row=0;row<dataSource[i].length;row++)
|
---|
105 | {
|
---|
106 | rows=dataSource[i][row].split(',');
|
---|
107 | Temp[row]=rows[0];
|
---|
108 | dataGraph[i].push(parseFloat(rows[4])||parseFloat('0'));
|
---|
109 | for(T=0;T<Temp.length;T++)
|
---|
110 | {
|
---|
111 | rowMin=Temp[T].split(':');
|
---|
112 | Min.push(parseInt(rowMin[1]));
|
---|
113 | }
|
---|
114 | for(T1=0;T1<Temp.length;T1++)
|
---|
115 | {
|
---|
116 | rowHour = Temp[T1].split('T');
|
---|
117 | Hour.push(parseFloat(rowHour[1]));
|
---|
118 | }
|
---|
119 | for(merge=1;merge<Temp.length-1;merge++)
|
---|
120 | {
|
---|
121 | if(Hour[merge]==0)
|
---|
122 | {
|
---|
123 | if(Min[merge]==8)
|
---|
124 | {
|
---|
125 | HourMin.push(Hour[merge]+24+'.08');
|
---|
126 | }
|
---|
127 | else
|
---|
128 | HourMin.push(Hour[merge]+24+Min[merge]);
|
---|
129 | }
|
---|
130 | else if(Hour[merge]==1)
|
---|
131 | {
|
---|
132 | if(Min[merge]==8)
|
---|
133 | {
|
---|
134 | HourMin.push(Hour[merge]+24+'.08');
|
---|
135 | }
|
---|
136 | else
|
---|
137 | HourMin.push(Hour[merge]+24+Min[merge]);
|
---|
138 | }
|
---|
139 | else if(Hour[merge]==2)
|
---|
140 | {
|
---|
141 | if(Min[merge]==8)
|
---|
142 | {
|
---|
143 | HourMin.push(Hour[merge]+24+'.08');
|
---|
144 | }
|
---|
145 | else
|
---|
146 | HourMin.push(Hour[merge]+24+Min[merge]);
|
---|
147 | }
|
---|
148 | else if(Hour[merge]==3)
|
---|
149 | {
|
---|
150 | if(Min[merge]==8)
|
---|
151 | {
|
---|
152 | HourMin.push(Hour[merge]+24+'.08');
|
---|
153 | }
|
---|
154 | else
|
---|
155 | HourMin.push(Hour[merge]+24+Min[merge]);
|
---|
156 | }
|
---|
157 | else if(Hour[merge]==4)
|
---|
158 | {
|
---|
159 | if(Min[merge]==8)
|
---|
160 | {
|
---|
161 | HourMin.push(Hour[merge]+24+'.08');
|
---|
162 | }
|
---|
163 | else
|
---|
164 | HourMin.push(Hour[merge]+24+Min[merge]);
|
---|
165 | }
|
---|
166 | else if(Hour[merge]==5)
|
---|
167 | {
|
---|
168 | if(Min[merge]==8)
|
---|
169 | {
|
---|
170 | HourMin.push(Hour[merge]+24+'.08');
|
---|
171 | }
|
---|
172 | else
|
---|
173 | HourMin.push(Hour[merge]+24+Min[merge]);
|
---|
174 | }
|
---|
175 | else if(Hour[merge]==6)
|
---|
176 | {
|
---|
177 | if(Min[merge]==8)
|
---|
178 | {
|
---|
179 | HourMin.push(Hour[merge]+24+'.08');
|
---|
180 | }
|
---|
181 | else
|
---|
182 | HourMin.push(Hour[merge]+24+Min[merge]);
|
---|
183 | }
|
---|
184 | else if(Hour[merge]==7)
|
---|
185 | {
|
---|
186 | if(Min[merge]==8)
|
---|
187 | {
|
---|
188 | HourMin.push(Hour[merge]+24+'.08');
|
---|
189 | }
|
---|
190 | else
|
---|
191 | HourMin.push(Hour[merge]+24+Min[merge]);
|
---|
192 | }
|
---|
193 | else if(Hour[merge]==8)
|
---|
194 | {
|
---|
195 | if(Min[merge]==8)
|
---|
196 | {
|
---|
197 | HourMin.push(Hour[merge]+24+'.08');
|
---|
198 | }
|
---|
199 | else
|
---|
200 | HourMin.push(Hour[merge]+24+Min[merge]);
|
---|
201 | }
|
---|
202 | else if(Min[merge]==8)
|
---|
203 | {
|
---|
204 | HourMin.push(Hour[merge]+'.08');
|
---|
205 | }
|
---|
206 | else
|
---|
207 | HourMin.push(Hour[merge]+'.'+Min[merge]);
|
---|
208 |
|
---|
209 | }
|
---|
210 | Time[i].push(HourMin[row]);
|
---|
211 |
|
---|
212 | }
|
---|
213 | for(Graph=0;Graph<dataGraph[i].length;Graph++)
|
---|
214 | {
|
---|
215 | chart.series[i].addPoint({ // series[0] means index of zero in data;
|
---|
216 | x:Time[i][Graph], // Time
|
---|
217 | y:dataGraph[i][Graph] // Value
|
---|
218 | })
|
---|
219 | }
|
---|
220 | $('#data').append(i + ": " + source[i] + ' Time ' + Time[i]);
|
---|
221 | }
|
---|
222 |
|
---|
223 | } |
---|