source: schedule/js/chart.js@ 16628

Last change on this file since 16628 was 16628, checked in by tanio, 11 years ago
File size: 3.4 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 alert("status is " + XML.status);
39
40 };
41 XML.send();
42}
43
44function displayXMLData(dataSource, source)
45{
46 var options =
47 {
48 chart: {
49 renderTo: 'container' /* display to div Graph*/
50
51 },
52
53 xAxis: {
54 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"]
55 },
56 series:[], /* array of Data */
57
58 remove:function()
59 {
60 return false;
61 },
62
63 exporting: { /*--------------------*/
64 buttons: { /* */
65 exportButton: { /* Export */
66 menuItems: null, /* to */
67 onclick: function() { /* PNG.file */
68 this.exportChart(); /*--------------------*/
69 }
70 }
71 }
72 },
73 plotOptions : {
74
75 series : {
76 lineWidth: 3,
77
78 marker : {
79 enabled:false
80 }
81 }
82 }
83 };
84 //This function splits the lines of data per data source
85 var dataGraph = new Array(source.length);
86 var Time = new Array(source.length);
87 var Temp = new Array(source.length);
88 var colonTime = new Array(source.length);
89 var colonMin = new Array(source.length);
90 var Hour = new Array(source.length);
91 for (i=0; i<source.length; i++)
92 {
93 dataGraph[i] = new Array(); //dataGraph contains the individual points for each source i
94 Time[i] = new Array(); // Time contains the individual time for each sources.
95 //Temp[i] = new Array();
96 //colonTime[i] = new Array();
97 //colonMin[i] = new Array();
98 //Hour[i] = new Array();
99 for(row=0;row<dataSource[i].length;row++)
100 {
101 rows=line[row].split(',');
102 dataGraph[i].push(parseFloat(rows[4])||parseFloat('0'));
103 Temp.push(rows[0]);
104 for(TempTime=0;TempTime<Temp.length;TempTime++)
105 {
106 rowTime=Temp[TempTime].split(':');
107 colonTime.push(rowTime[0]); // Contains the data of Time
108 colonMin.push(parseInt(rowTime[1]/60*100)||parseFloat('0')); // Contains the data of minutes
109 for(TempHour=0;TempHour<colonTime.length;TempHour++)
110 {
111 rowHour=colonTime[TempHour].split('T');
112 Hour.push(parseFloat(rowHour[1])||parseFloat('0'));
113 Time[i].push(Hour[TempHour]+'.'+colonMin[TempTime]);
114 }
115
116
117 }
118 }
119 $('#data').append(i + ": " + source[i] + ' GRAPH DATA ' + dataGraph[i] + ' Time '+ Time[i]);
120 }
121}
Note: See TracBrowser for help on using the repository browser.