source: schedule/js/chart.js@ 16718

Last change on this file since 16718 was 16718, checked in by tanio, 11 years ago
File size: 3.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
10 //$('#data').append('1st'+source);
11 }
12}
13/*function getDate(day){
14
15 var days = day;
16 return days;
17 }*/
18
19function 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
50function 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 TempHour = new Array();
98 var chart = new Highcharts.Chart(options);
99 for (i=0; i<source.length; i++)
100 {
101 dataGraph[i] = new Array(); //dataGraph contains the individual points for each source i
102 Time[i] = new Array(); // Time contains the individual time for each sources.
103 chart.addSeries({name:source[i], data:[]}); // created a series of data and add name of displayed source
104
105 for(row=0;row<dataSource[i].length;row++)
106 {
107 rows=dataSource[i][row].split(',');
108 Temp[row]=rows[0];
109 dataGraph[i].push(parseFloat(rows[4])||parseFloat('0'));
110 dateTime = new Date(rows[0]);
111 Time[i].push(parseFloat(get.Hours())+'.'+parseInt(get.Minutes()/60*100));
112
113 }
114 for(Graph=0;Graph<dataGraph[i].length;Graph++)
115 {
116 chart.series[i].addPoint({ // series[0] means index of zero in data;
117 x:Time[i][Graph], // Time
118 y:dataGraph[i][Graph] // Value
119 })
120 }
121 //$('#data').append(i + ": " + source[i] + ' Time ' + Time[i]);
122 }
123
124}
Note: See TracBrowser for help on using the repository browser.