source: schedule/js/chart.js@ 18185

Last change on this file since 18185 was 17547, checked in by tose, 11 years ago
Removed chart function
File size: 2.7 KB
Line 
1function 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 {
7 source.push($(this).text());
8
9 });
10 //console.log(source);
11 for (i = 0; i<source.length; i++)
12 {
13 GetXMLData(i, source);
14 }
15}
16function GetXMLData(index, source)
17{
18 var XML;
19 XML = new XMLHttpRequest();
20 //NOTE: previous errors on the request was caused by appending "http://www.fact-project.org"
21 XML.open("GET","/smartfact/index.php?source="+escape(source[index])+"&time="+year+"-"+month+"-"+day,true);
22 dataSource = new Array();
23 XML.onload=function()
24 {
25 if (XML.status==200)
26 {
27 line=XML.responseText.split('\n');
28 dataSource.push(line);
29 if (dataSource.length == source.length)
30 {
31 displayXMLData(dataSource, source); //this will be called when the last data from the list is read
32 }
33 }
34 else
35 alert("status is " + XML.status);
36 };
37
38 XML.send();
39}
40
41function displayXMLData(dataSource, source)
42{
43 var options =
44 {
45 chart: {
46 renderTo: 'Graph' /* display to div Graph*/
47
48 },
49
50 xAxis: {
51 categories:[]
52 },
53 series:[], /* array of Data */
54
55 remove:function()
56 {
57 return false;
58 },
59
60 exporting: { /*--------------------*/
61 buttons: { /* */
62 exportButton: { /* Export */
63 menuItems: null, /* to */
64 onclick: function() { /* PNG.file */
65 this.exportChart(); /*--------------------*/
66 }
67 }
68 }
69 },
70 plotOptions : {
71
72 series : {
73 lineWidth: 3,
74
75 marker : {
76 enabled:false
77 }
78 }
79 }
80 };
81 //This function splits the lines of data per data source
82 var dataGraph = new Array(source.length);
83 var Time = new Array(source.length);
84 var HourMin = new Array();
85 var chart = new Highcharts.Chart(options);
86 for (i=0; i<source.length; i++)
87 {
88 dataGraph[i] = new Array(); //dataGraph contains the individual points for each source i
89 Time[i] = new Array(); // Time contains the individual time for each sources.
90 chart.addSeries({name:source[i], data:[]}); // created a series of data and add name of displayed source
91
92 for(row=0;row<dataSource[i].length;row++)
93 {
94 rows=dataSource[i][row].split(',');
95 dataGraph[i].push(parseFloat(rows[4])||parseFloat('0'));
96 dateTime = new Date(rows[0]);
97 Time[i].push(parseFloat(dateTime.getHours())+'.'+parseInt(dateTime.getMinutes()/60*100));
98
99 }
100 for(Graph=0;Graph<dataGraph[i].length;Graph++)
101 {
102 chart.series[i].addPoint({ // series[0] means index of zero in data;
103 x:Time[i][Graph], // Time
104 y:dataGraph[i][Graph] // Value
105 })
106 }
107 }
108
109}
Note: See TracBrowser for help on using the repository browser.