1 | function GetData()
|
---|
2 | {
|
---|
3 | var source = new Array();
|
---|
4 | //calls the xml request in a loop based on the current sources
|
---|
5 | $('#box2View option').each(function(){
|
---|
6 | source.push($(this).text());
|
---|
7 |
|
---|
8 | });
|
---|
9 | console.log(source);
|
---|
10 | for (i = 0; i<source.length; i++)
|
---|
11 | {
|
---|
12 | GetXMLData(i, source);
|
---|
13 | }
|
---|
14 | }
|
---|
15 | function GetXMLData(index, source)
|
---|
16 | {
|
---|
17 | var XML;
|
---|
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 | line=XML.responseText.split('\n');
|
---|
27 | dataSource.push(line);
|
---|
28 | if (dataSource.length == source.length)
|
---|
29 | {
|
---|
30 | displayXMLData(dataSource, source); //this will be called when the last data from the list is read
|
---|
31 | }
|
---|
32 | }
|
---|
33 | else
|
---|
34 | alert("status is " + XML.status);
|
---|
35 | };
|
---|
36 |
|
---|
37 | XML.send();
|
---|
38 | }
|
---|
39 |
|
---|
40 | function displayXMLData(dataSource, source)
|
---|
41 | {
|
---|
42 | var options =
|
---|
43 | {
|
---|
44 | chart: {
|
---|
45 | renderTo: 'Graph' /* display to div Graph*/
|
---|
46 |
|
---|
47 | },
|
---|
48 |
|
---|
49 | xAxis: {
|
---|
50 | categories:[]
|
---|
51 | },
|
---|
52 | series:[], /* array of Data */
|
---|
53 |
|
---|
54 | remove:function()
|
---|
55 | {
|
---|
56 | return false;
|
---|
57 | },
|
---|
58 |
|
---|
59 | exporting: { /*--------------------*/
|
---|
60 | buttons: { /* */
|
---|
61 | exportButton: { /* Export */
|
---|
62 | menuItems: null, /* to */
|
---|
63 | onclick: function() { /* PNG.file */
|
---|
64 | this.exportChart(); /*--------------------*/
|
---|
65 | }
|
---|
66 | }
|
---|
67 | }
|
---|
68 | },
|
---|
69 | plotOptions : {
|
---|
70 |
|
---|
71 | series : {
|
---|
72 | lineWidth: 3,
|
---|
73 |
|
---|
74 | marker : {
|
---|
75 | enabled:false
|
---|
76 | }
|
---|
77 | }
|
---|
78 | }
|
---|
79 | };
|
---|
80 | //This function splits the lines of data per data source
|
---|
81 | var dataGraph = new Array(source.length);
|
---|
82 | var Time = new Array(source.length);
|
---|
83 | var HourMin = new Array();
|
---|
84 | var chart = new Highcharts.Chart(options);
|
---|
85 | for (i=0; i<source.length; i++)
|
---|
86 | {
|
---|
87 | dataGraph[i] = new Array(); //dataGraph contains the individual points for each source i
|
---|
88 | Time[i] = new Array(); // Time contains the individual time for each sources.
|
---|
89 | chart.addSeries({name:source[i], data:[]}); // created a series of data and add name of displayed source
|
---|
90 |
|
---|
91 | for(row=0;row<dataSource[i].length;row++)
|
---|
92 | {
|
---|
93 | rows=dataSource[i][row].split(',');
|
---|
94 | dataGraph[i].push(parseFloat(rows[4])||parseFloat('0'));
|
---|
95 | dateTime = new Date(rows[0]);
|
---|
96 | Time[i].push(parseFloat(dateTime.getHours())+'.'+parseInt(dateTime.getMinutes()/60*100));
|
---|
97 |
|
---|
98 | }
|
---|
99 | for(Graph=0;Graph<dataGraph[i].length;Graph++)
|
---|
100 | {
|
---|
101 | chart.series[i].addPoint({ // series[0] means index of zero in data;
|
---|
102 | x:Time[i][Graph], // Time
|
---|
103 | y:dataGraph[i][Graph] // Value
|
---|
104 | })
|
---|
105 | }
|
---|
106 | }
|
---|
107 |
|
---|
108 | } |
---|