Advertisement
Guest User

Untitled

a guest
Feb 26th, 2016
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.87 KB | None | 0 0
  1. <script type="text/javascript">
  2. $.get('dados/perfiskwh.csv', function (csvFile) {
  3. var data = parseCSVData(csvFile);
  4. var highchartsOptions = Highcharts.setOptions({
  5. lang: {
  6. loading: 'Aguarde...',
  7. months: ['Janeiro', 'Fevereiro', 'Março', 'Abril', 'Maio', 'Junho', 'Julho', 'Agosto', 'Setembro', 'Outubro', 'Novembro', 'Dezembro'],
  8. weekdays: ['Domingo', 'Segunda-feira', 'Terça-feira', 'Quarta-feira', 'Quinta-feira', 'Sexta-feira', 'Sábado'],
  9. shortMonths: ['Jan', 'Fev', 'Mar', 'Abr', 'Mai', 'Jun', 'Jul', 'Ago', 'Set', 'Out', 'Nov', 'Dez'],
  10. exportButtonTitle: "Exportar",
  11. printButtonTitle: "Imprimir",
  12. rangeSelectorFrom: "De",
  13. rangeSelectorTo: "Até",
  14. rangeSelectorZoom: "Periodo",
  15. downloadPNG: 'Descarregar gráfico como imagem PNG',
  16. downloadJPEG: 'Descarregar gráfico como imagem JPEG',
  17. downloadSVG: 'Descarregar gráfico como imagem SVG',
  18. downloadPDF: 'Salvar em documento PDF',
  19. contextButtonTitle: 'Opções',
  20. noData: 'Sem dados para mostrar',
  21. printChart: 'Imprimir gráfico',
  22. numericSymbols: null,
  23. // resetZoom: "Reset",
  24. // resetZoomTitle: "Reset,
  25. thousandsSep: ".",
  26. decimalPoint: ','
  27. }
  28. }
  29. );
  30. $('#container').highcharts('StockChart', {
  31. navigation: {
  32. buttonOptions: {
  33. enabled: true,
  34. }
  35. },
  36. colors:[
  37. '#993333',
  38. '#404040',
  39. '#003366',
  40. '#006600',
  41. '#CC3300'
  42. ],
  43. credits: {
  44. enabled: false
  45. },
  46. rangeSelector : {
  47. selected: 1,
  48. allButtonsEnabled: true,
  49. buttons: [{
  50. type: 'day',
  51. count: 1,
  52. text: '1 dia'
  53. }, {
  54. type: 'week',
  55. count: 1,
  56. text: '1 Semana'
  57. }, {
  58. type: 'all',
  59. text: 'Tudo'
  60. }],
  61. buttonTheme: {
  62. width: 75,
  63. style: {
  64. color: '#333',
  65. fontWeight: 'bold',
  66. fontSize: '14px',
  67. fontFamily: 'Trebuchet MS, Verdana, sans-serif'
  68.  
  69. },
  70. },
  71.  
  72. },
  73. chart: {
  74. renderTo: 'container',
  75. backgroundColor: {
  76. linearGradient: [500, 400, 250, 0],
  77. stops: [
  78. [0, '#F0F7FF'],
  79. [1, '#F0F7FF']
  80. ]
  81. },
  82. style: {
  83. color: '#333',
  84. fontWeight: 'bold',
  85. fontSize: '14px',
  86. fontFamily: 'Trebuchet MS, Verdana, sans-serif'
  87.  
  88. },
  89. type: 'spline'
  90. },
  91.  
  92. title: {
  93. text: 'Perfis de Consumos',
  94. style: {
  95. color: '#333',
  96. fontWeight: 'bold',
  97. fontSize: '20px',
  98. fontFamily: 'Trebuchet MS, Verdana, sans-serif'
  99.  
  100. }
  101. },
  102. xAxis: {
  103. labels: {
  104. style: {
  105. color: 'black',
  106. fontWeight: 'bold',
  107. fontSize: '12px',
  108. fontFamily: 'Trebuchet MS, Verdana, sans-serif'
  109. }
  110. },
  111. type: 'datetime',
  112. tickInterval: 3600 * 1000,
  113.  
  114.  
  115. },
  116. tooltip: {
  117. valueDecimals: 1,
  118. valueSuffix: ' KWh'
  119. },
  120. yAxis: {
  121. labels: {
  122. style: {
  123. color: 'black',
  124. fontWeight: 'bold',
  125. fontSize: '12px',
  126. fontFamily: 'Trebuchet MS, Verdana, sans-serif'
  127. }
  128. },
  129. opposite: false,
  130. title: {
  131. text: 'Consumos da Energia [KWh]',
  132. style: {
  133. color: '#333',
  134. fontWeight: 'bold',
  135. fontSize: '16px',
  136. fontFamily: 'Trebuchet MS, Verdana, sans-serif'
  137. }
  138. }
  139. },
  140. navigator:{
  141. xAxis: {
  142. style: {
  143. color: '#333',
  144. fontWeight: 'bold',
  145. fontSize: '16px',
  146. fontFamily: 'Trebuchet MS, Verdana, sans-serif'
  147. }
  148. },
  149. enabled: true,
  150. handles: {
  151. backgroundColor: 'Black',
  152. borderColor: 'White'
  153. },
  154. series: {
  155. color: '#0000FF',
  156. lineWidth: 1
  157. },
  158. outlineColor: 'black',
  159. outlineWidth: 1,
  160. },
  161. series: [{
  162. name:'Distribuidor',
  163. data: data[0],
  164. }, {
  165. name: 'Edificios',
  166. data: data[1]
  167. }, {
  168. name: 'Avac',
  169. data: data[2]
  170. }, {
  171. name: 'Aqs',
  172. data: data[3]
  173. }, {
  174. name: 'FotoVoltaico',
  175. data: data[4]
  176. }]
  177. });
  178. });
  179.  
  180. function parseCSVData(csvFile) {
  181. //Array para armazenar dados do Gráfico
  182. var Geral= [];
  183. var Distribuidor= [];
  184. var AVAC= [];
  185. var FotoVoltaico= [];
  186. var AQS= [];
  187.  
  188. var Data_inicio = "January 1, 2014";
  189. var Data_hoje = new Date();
  190.  
  191. //Separar os dados do CSV em linhas
  192. var lines= csvFile.split("n");
  193.  
  194. //Verifica todas as linhas do CSV
  195. $.each(lines, function (lineNumber, line){
  196. if(lineNumber !=0){ //Salta a linha do cabeçalho
  197. var fields = line.split(";");
  198. if(fields.length==6 && Date.parse(fields[0]) >= Date.parse(Data_inicio) && Date.parse(fields[0]) <= Date.parse(Data_hoje)) {//Salta as linhas invalidas e começa na data especificada até ao presente dia
  199. var timestamp = Date.parse(fields[0]);
  200. var data1 = parseInt(fields[1]);
  201. var data2 = parseInt(fields[2]);
  202. var data3 = parseInt(fields[3]);
  203. var data4 = parseInt(fields[4]);
  204. var data5 = parseInt(fields[5]);
  205.  
  206. Geral.push([timestamp, data1]);
  207. Distribuidor.push([timestamp, data2]);
  208. AVAC.push([timestamp, data3]);
  209. FotoVoltaico.push([timestamp, data4]);
  210. AQS.push([timestamp, data5]);
  211. }
  212. }
  213. });
  214. return [Geral,Distribuidor,AVAC,FotoVoltaico,AQS];
  215. }
  216.  
  217. </script>
  218.  
  219. <?php
  220.  
  221. $db_user = "";
  222. $db_pass = "";
  223. $db_host = "";
  224. $db_name = "";
  225. $table = "";
  226.  
  227. $con = mysql_connect($db_host, $db_user, $db_pass);
  228.  
  229. mysql_select_db($db_name , $con);
  230.  
  231. $query = mysql_query(" SELECT `ts`,`value` FROM `$table` ");
  232.  
  233. $category = array();
  234. $category['name'] = 'ts';
  235. $series1 = array();
  236. $series1['name'] = 'kwh';
  237.  
  238. while($r = mysql_fetch_array($query)){
  239. $category['data'][] = $r['ts'];
  240. $series1 ['data'][] = $r['value'];
  241. }
  242.  
  243. $result = array();
  244. array_push($result,$category);
  245. array_push($result,$series1);
  246.  
  247. print json_encode($result, JSON_NUMERIC_CHECK);
  248.  
  249. mysql_close($con);
  250.  
  251. ?>
  252.  
  253. <!DOCTYPE HTML>
  254. <html>
  255. <head>
  256. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  257. <title>Column chart with data from MySQL using Highcharts</title>
  258. <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
  259. <script type="text/javascript">
  260. $(document).ready(function() {
  261. var options = {
  262. chart: {
  263. renderTo: 'container',
  264. type: 'column',
  265. marginRight: 130,
  266. marginBottom: 25
  267. },
  268. title: {
  269. text: 'Project Requests',
  270. x: -20 //center
  271. },
  272. subtitle: {
  273. text: '',
  274. x: -20
  275. },
  276. xAxis: {
  277. categories: []
  278. },
  279. yAxis: {
  280. title: {
  281. text: 'Requests'
  282. },
  283. plotLines: [{
  284. value: 0,
  285. width: 1,
  286. color: '#808080'
  287. }]
  288. },
  289. tooltip: {
  290. formatter: function() {
  291. return '<b>'+ this.series.name +'</b><br/>'+
  292. this.x +': '+ this.y;
  293. }
  294. },
  295. legend: {
  296. layout: 'vertical',
  297. align: 'right',
  298. verticalAlign: 'top',
  299. x: -10,
  300. y: 100,
  301. borderWidth: 0
  302. },
  303. series: []
  304. }
  305.  
  306. $.getJSON("genenergy3-sensor1.php", function(json) {
  307. options.xAxis.categories = json[0]['data'];
  308. options.series[0] = json[1];
  309. chart = new Highcharts.Chart(options);
  310. });
  311. });
  312. </script>
  313. <script src="http://code.highcharts.com/highcharts.js"></script>
  314. <script src="http://code.highcharts.com/modules/exporting.js"></script>
  315. </head>
  316. <body>
  317. <div id="container" style="min-width: 400px; height: 400px; margin: 0 auto"></div>
  318. </body>
  319. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement