source: schedule/js/chart.js@ 16654

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