actuator_chart_D.html 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752
  1. <!-- 宣告我們要套用模板 -->
  2. {% extends "base.html" %}
  3. {% block title %}{{ title }}{% endblock %}
  4. {% block script %}
  5. <!--引入 echarts.js -->
  6. <script src="https://cdn.staticfile.org/echarts/4.3.0/echarts.min.js"></script>
  7. <script src='https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.5.0/Chart.min.js'></script>
  8. <script src='https://cdnjs.cloudflare.com/ajax/libs/hammer.js/2.0.8/hammer.js'></script>
  9. <script src="https://cdnjs.cloudflare.com/ajax/libs/chartjs-plugin-zoom/0.3.0/Chart.Zoom.min.js"></script>
  10. <script language="JavaScript">
  11. var tank = '{{tank}}';
  12. var sensor_name = '{{sensor_name}}';
  13. var status = '{{status}}';
  14. var username = '{{username}}';
  15. var tid = '{{tid}}';
  16. $(document).ready(function(){
  17. $("#coffee_title_pc").text(' 乾燥槽致動器圖表');
  18. $("#coffee_title_phone").text(' 致動器');
  19. $('#navbarDropdown_user_pc').text(username);
  20. $('#navbarDropdown_user_phone').text(username);
  21. });
  22. </script>
  23. {% endblock %}
  24. {% block main %}
  25. <div class="album py-5 bg-light">
  26. <div class="container">
  27. <div class="row row-cols-1 row-cols-sm-1 row-cols-md-1 g-3">
  28. <div class="col">
  29. <div class="card shadow-sm">
  30. <div class="card-body">
  31. <div class="d-flex justify-content-between align-items-center">
  32. <table style="margin: auto; border:3px gray solid; width: 80%; text-align: center;" cellpadding="6" rules='ALL'>
  33. <tr>
  34. <td style="border:1px gray solid;">
  35. {% if tid == '2'%}
  36. <select id="tank_num">
  37. <option value="D1">乾燥槽_1</option>
  38. <option value="D2" selected>乾燥槽_2</option>
  39. <option value="D3">乾燥槽_3</option>
  40. <option value="D4">乾燥槽_4</option>
  41. <option value="D5">乾燥槽_5</option>
  42. <option value="D6">乾燥槽_6</option>
  43. <option value="D7">乾燥槽_7</option>
  44. <option value="D8">乾燥槽_8</option>
  45. <option value="D9">乾燥槽_9</option>
  46. <option value="D10">乾燥槽_10</option>
  47. <option value="D11">乾燥槽_11</option>
  48. <option value="D12">乾燥槽_12</option>
  49. </select>
  50. {% elif tid == '3'%}
  51. <select id="tank_num">
  52. <option value="D1">乾燥槽_1</option>
  53. <option value="D2">乾燥槽_2</option>
  54. <option value="D3" selected>乾燥槽_3</option>
  55. <option value="D4">乾燥槽_4</option>
  56. <option value="D5">乾燥槽_5</option>
  57. <option value="D6">乾燥槽_6</option>
  58. <option value="D7">乾燥槽_7</option>
  59. <option value="D8">乾燥槽_8</option>
  60. <option value="D9">乾燥槽_9</option>
  61. <option value="D10">乾燥槽_10</option>
  62. <option value="D11">乾燥槽_11</option>
  63. <option value="D12">乾燥槽_12</option>
  64. </select>
  65. {% elif tid == '4'%}
  66. <select id="tank_num">
  67. <option value="D1">乾燥槽_1</option>
  68. <option value="D2">乾燥槽_2</option>
  69. <option value="D3">乾燥槽_3</option>
  70. <option value="D4" selected>乾燥槽_4</option>
  71. <option value="D5">乾燥槽_5</option>
  72. <option value="D6">乾燥槽_6</option>
  73. <option value="D7">乾燥槽_7</option>
  74. <option value="D8">乾燥槽_8</option>
  75. <option value="D9">乾燥槽_9</option>
  76. <option value="D10">乾燥槽_10</option>
  77. <option value="D11">乾燥槽_11</option>
  78. <option value="D12">乾燥槽_12</option>
  79. </select>
  80. {% elif tid == '5'%}
  81. <select id="tank_num">
  82. <option value="D1">乾燥槽_1</option>
  83. <option value="D2">乾燥槽_2</option>
  84. <option value="D3">乾燥槽_3</option>
  85. <option value="D4">乾燥槽_4</option>
  86. <option value="D5" selected>乾燥槽_5</option>
  87. <option value="D6">乾燥槽_6</option>
  88. <option value="D7">乾燥槽_7</option>
  89. <option value="D8">乾燥槽_8</option>
  90. <option value="D9">乾燥槽_9</option>
  91. <option value="D10">乾燥槽_10</option>
  92. <option value="D11">乾燥槽_11</option>
  93. <option value="D12">乾燥槽_12</option>
  94. </select>
  95. {% elif tid == '6'%}
  96. <select id="tank_num">
  97. <option value="D1">乾燥槽_1</option>
  98. <option value="D2">乾燥槽_2</option>
  99. <option value="D3">乾燥槽_3</option>
  100. <option value="D4">乾燥槽_4</option>
  101. <option value="D5">乾燥槽_5</option>
  102. <option value="D6" selected>乾燥槽_6</option>
  103. <option value="D7">乾燥槽_7</option>
  104. <option value="D8">乾燥槽_8</option>
  105. <option value="D9">乾燥槽_9</option>
  106. <option value="D10">乾燥槽_10</option>
  107. <option value="D11">乾燥槽_11</option>
  108. <option value="D12">乾燥槽_12</option>
  109. </select>
  110. {% elif tid == '7'%}
  111. <select id="tank_num">
  112. <option value="D1">乾燥槽_1</option>
  113. <option value="D2">乾燥槽_2</option>
  114. <option value="D3">乾燥槽_3</option>
  115. <option value="D4">乾燥槽_4</option>
  116. <option value="D5">乾燥槽_5</option>
  117. <option value="D6">乾燥槽_6</option>
  118. <option value="D7" selected>乾燥槽_7</option>
  119. <option value="D8">乾燥槽_8</option>
  120. <option value="D9">乾燥槽_9</option>
  121. <option value="D10">乾燥槽_10</option>
  122. <option value="D11">乾燥槽_11</option>
  123. <option value="D12">乾燥槽_12</option>
  124. </select>
  125. {% elif tid == '8'%}
  126. <select id="tank_num">
  127. <option value="D1">乾燥槽_1</option>
  128. <option value="D2">乾燥槽_2</option>
  129. <option value="D3">乾燥槽_3</option>
  130. <option value="D4">乾燥槽_4</option>
  131. <option value="D5">乾燥槽_5</option>
  132. <option value="D6">乾燥槽_6</option>
  133. <option value="D7">乾燥槽_7</option>
  134. <option value="D8" selected>乾燥槽_8</option>
  135. <option value="D9">乾燥槽_9</option>
  136. <option value="D10">乾燥槽_10</option>
  137. <option value="D11">乾燥槽_11</option>
  138. <option value="D12">乾燥槽_12</option>
  139. </select>
  140. {% elif tid == '9'%}
  141. <select id="tank_num">
  142. <option value="D1">乾燥槽_1</option>
  143. <option value="D2">乾燥槽_2</option>
  144. <option value="D3">乾燥槽_3</option>
  145. <option value="D4">乾燥槽_4</option>
  146. <option value="D5">乾燥槽_5</option>
  147. <option value="D6">乾燥槽_6</option>
  148. <option value="D7">乾燥槽_7</option>
  149. <option value="D8">乾燥槽_8</option>
  150. <option value="D9" selected>乾燥槽_9</option>
  151. <option value="D10">乾燥槽_10</option>
  152. <option value="D11">乾燥槽_11</option>
  153. <option value="D12">乾燥槽_12</option>
  154. </select>
  155. {% elif tid == '10'%}
  156. <select id="tank_num">
  157. <option value="D1">乾燥槽_1</option>
  158. <option value="D2">乾燥槽_2</option>
  159. <option value="D3">乾燥槽_3</option>
  160. <option value="D4">乾燥槽_4</option>
  161. <option value="D5">乾燥槽_5</option>
  162. <option value="D6">乾燥槽_6</option>
  163. <option value="D7">乾燥槽_7</option>
  164. <option value="D8">乾燥槽_8</option>
  165. <option value="D9">乾燥槽_9</option>
  166. <option value="D10" selected>乾燥槽_10</option>
  167. <option value="D11">乾燥槽_11</option>
  168. <option value="D12">乾燥槽_12</option>
  169. </select>
  170. {% elif tid == '11'%}
  171. <select id="tank_num">
  172. <option value="D1">乾燥槽_1</option>
  173. <option value="D2">乾燥槽_2</option>
  174. <option value="D3">乾燥槽_3</option>
  175. <option value="D4">乾燥槽_4</option>
  176. <option value="D5">乾燥槽_5</option>
  177. <option value="D6">乾燥槽_6</option>
  178. <option value="D7">乾燥槽_7</option>
  179. <option value="D8">乾燥槽_8</option>
  180. <option value="D9">乾燥槽_9</option>
  181. <option value="D10">乾燥槽_10</option>
  182. <option value="D11" selected>乾燥槽_11</option>
  183. <option value="D12">乾燥槽_12</option>
  184. </select>
  185. {% elif tid == '12'%}
  186. <select id="tank_num">
  187. <option value="D1">乾燥槽_1</option>
  188. <option value="D2">乾燥槽_2</option>
  189. <option value="D3">乾燥槽_3</option>
  190. <option value="D4">乾燥槽_4</option>
  191. <option value="D5">乾燥槽_5</option>
  192. <option value="D6">乾燥槽_6</option>
  193. <option value="D7">乾燥槽_7</option>
  194. <option value="D8">乾燥槽_8</option>
  195. <option value="D9">乾燥槽_9</option>
  196. <option value="D10">乾燥槽_10</option>
  197. <option value="D11">乾燥槽_11</option>
  198. <option value="D12" selected>乾燥槽_12</option>
  199. </select>
  200. {% else %}
  201. <select id="tank_num">
  202. <option value="D1" selected>乾燥槽_1</option>
  203. <option value="D2">乾燥槽_2</option>
  204. <option value="D3">乾燥槽_3</option>
  205. <option value="D4">乾燥槽_4</option>
  206. <option value="D5">乾燥槽_5</option>
  207. <option value="D6">乾燥槽_6</option>
  208. <option value="D7">乾燥槽_7</option>
  209. <option value="D8">乾燥槽_8</option>
  210. <option value="D9">乾燥槽_9</option>
  211. <option value="D10">乾燥槽_10</option>
  212. <option value="D11">乾燥槽_11</option>
  213. <option value="D12">乾燥槽_12</option>
  214. </select>
  215. {% endif %}
  216. {% if sensor_name=='vacuum' %}
  217. <select id="sensors">
  218. <option value="vacuum" selected>真空吸料機</option>
  219. <option value="threewayvalve_input">入料三通閥</option>
  220. <option value="diskvalve">蝴蝶閥</option>
  221. <option value="solenoid_disinfect">桶內消毒電磁閥</option>
  222. <option value="solenoid_water_out">排水廢水電磁閥</option>
  223. <option value="motor">馬達</option>
  224. <option value="vacuum_pump">乾燥真空機</option>
  225. <option value="heater1">加熱器1</option>
  226. <option value="heater2">加熱器2</option>
  227. <option value="solenoid_outer_water">保溫夾層進水電磁閥</option>
  228. <option value="Warning_Light">警示燈</option>
  229. </select>
  230. {% elif sensor_name=='threewayvalve_input' %}
  231. <select id="sensors">
  232. <option value="vacuum" >真空吸料機</option>
  233. <option value="threewayvalve_input" selected>入料三通閥</option>
  234. <option value="diskvalve">蝴蝶閥</option>
  235. <option value="solenoid_disinfect">桶內消毒電磁閥</option>
  236. <option value="solenoid_water_out">排水廢水電磁閥</option>
  237. <option value="motor">馬達</option>
  238. <option value="vacuum_pump">乾燥真空機</option>
  239. <option value="heater1">加熱器1</option>
  240. <option value="heater2">加熱器2</option>
  241. <option value="solenoid_outer_water">保溫夾層進水電磁閥</option>
  242. <option value="Warning_Light">警示燈</option>
  243. </select>
  244. {% elif sensor_name=='diskvalve' %}
  245. <select id="sensors">
  246. <option value="vacuum" >真空吸料機</option>
  247. <option value="threewayvalve_input">入料三通閥</option>
  248. <option value="diskvalve" selected>蝴蝶閥</option>
  249. <option value="solenoid_disinfect">桶內消毒電磁閥</option>
  250. <option value="solenoid_water_out">排水廢水電磁閥</option>
  251. <option value="motor">馬達</option>
  252. <option value="vacuum_pump">乾燥真空機</option>
  253. <option value="heater1">加熱器1</option>
  254. <option value="heater2">加熱器2</option>
  255. <option value="solenoid_outer_water">保溫夾層進水電磁閥</option>
  256. <option value="Warning_Light">警示燈</option>
  257. </select>
  258. {% elif sensor_name=='solenoid_disinfect' %}
  259. <select id="sensors">
  260. <option value="vacuum" >真空吸料機</option>
  261. <option value="threewayvalve_input">入料三通閥</option>
  262. <option value="diskvalve">蝴蝶閥</option>
  263. <option value="solenoid_disinfect" selected>桶內消毒電磁閥</option>
  264. <option value="solenoid_water_out">排水廢水電磁閥</option>
  265. <option value="motor">馬達</option>
  266. <option value="vacuum_pump">乾燥真空機</option>
  267. <option value="heater1">加熱器1</option>
  268. <option value="heater2">加熱器2</option>
  269. <option value="solenoid_outer_water">保溫夾層進水電磁閥</option>
  270. <option value="Warning_Light">警示燈</option>
  271. </select>
  272. {% elif sensor_name=='solenoid_water_out' %}
  273. <select id="sensors">
  274. <option value="vacuum" >真空吸料機</option>
  275. <option value="threewayvalve_input">入料三通閥</option>
  276. <option value="diskvalve">蝴蝶閥</option>
  277. <option value="solenoid_disinfect">桶內消毒電磁閥</option>
  278. <option value="solenoid_water_out" selected>排水廢水電磁閥</option>
  279. <option value="motor">馬達</option>
  280. <option value="vacuum_pump">乾燥真空機</option>
  281. <option value="heater1">加熱器1</option>
  282. <option value="heater2">加熱器2</option>
  283. <option value="solenoid_outer_water">保溫夾層進水電磁閥</option>
  284. <option value="Warning_Light">警示燈</option>
  285. </select>
  286. {% elif sensor_name=='motor' %}
  287. <select id="sensors">
  288. <option value="vacuum" >真空吸料機</option>
  289. <option value="threewayvalve_input">入料三通閥</option>
  290. <option value="diskvalve">蝴蝶閥</option>
  291. <option value="solenoid_disinfect">桶內消毒電磁閥</option>
  292. <option value="solenoid_water_out">排水廢水電磁閥</option>
  293. <option value="motor" selected>馬達</option>
  294. <option value="vacuum_pump">乾燥真空機</option>
  295. <option value="heater1">加熱器1</option>
  296. <option value="heater2">加熱器2</option>
  297. <option value="solenoid_outer_water">保溫夾層進水電磁閥</option>
  298. <option value="Warning_Light">警示燈</option>
  299. </select>
  300. {% elif sensor_name=='vacuum_pump' %}
  301. <select id="sensors">
  302. <option value="vacuum" >真空吸料機</option>
  303. <option value="threewayvalve_input">入料三通閥</option>
  304. <option value="diskvalve">蝴蝶閥</option>
  305. <option value="solenoid_disinfect">桶內消毒電磁閥</option>
  306. <option value="solenoid_water_out">排水廢水電磁閥</option>
  307. <option value="motor">馬達</option>
  308. <option value="vacuum_pump" selected>乾燥真空機</option>
  309. <option value="heater1">加熱器1</option>
  310. <option value="heater2">加熱器2</option>
  311. <option value="solenoid_outer_water">保溫夾層進水電磁閥</option>
  312. <option value="Warning_Light">警示燈</option>
  313. </select>
  314. {% elif sensor_name=='heater1' %}
  315. <select id="sensors">
  316. <option value="vacuum" >真空吸料機</option>
  317. <option value="threewayvalve_input">入料三通閥</option>
  318. <option value="diskvalve">蝴蝶閥</option>
  319. <option value="solenoid_disinfect">桶內消毒電磁閥</option>
  320. <option value="solenoid_water_out">排水廢水電磁閥</option>
  321. <option value="motor">馬達</option>
  322. <option value="vacuum_pump">乾燥真空機</option>
  323. <option value="heater1" selected>加熱器1</option>
  324. <option value="heater2">加熱器2</option>
  325. <option value="solenoid_outer_water">保溫夾層進水電磁閥</option>
  326. <option value="Warning_Light">警示燈</option>
  327. </select>
  328. {% elif sensor_name=='heater2' %}
  329. <select id="sensors">
  330. <option value="vacuum" >真空吸料機</option>
  331. <option value="threewayvalve_input">入料三通閥</option>
  332. <option value="diskvalve">蝴蝶閥</option>
  333. <option value="solenoid_disinfect">桶內消毒電磁閥</option>
  334. <option value="solenoid_water_out">排水廢水電磁閥</option>
  335. <option value="motor">馬達</option>
  336. <option value="vacuum_pump">乾燥真空機</option>
  337. <option value="heater1">加熱器1</option>
  338. <option value="heater2" selected>加熱器2</option>
  339. <option value="solenoid_outer_water">保溫夾層進水電磁閥</option>
  340. <option value="Warning_Light">警示燈</option>
  341. </select>
  342. {% elif sensor_name=='solenoid_outer_water' %}
  343. <select id="sensors">
  344. <option value="vacuum" >真空吸料機</option>
  345. <option value="threewayvalve_input">入料三通閥</option>
  346. <option value="diskvalve">蝴蝶閥</option>
  347. <option value="solenoid_disinfect">桶內消毒電磁閥</option>
  348. <option value="solenoid_water_out">排水廢水電磁閥</option>
  349. <option value="motor">馬達</option>
  350. <option value="vacuum_pump">乾燥真空機</option>
  351. <option value="heater1">加熱器1</option>
  352. <option value="heater2">加熱器2</option>
  353. <option value="solenoid_outer_water" selected>保溫夾層進水電磁閥</option>
  354. <option value="Warning_Light">警示燈</option>
  355. </select>
  356. {% elif sensor_name=='Warning_Light' %}
  357. <select id="sensors">
  358. <option value="vacuum" >真空吸料機</option>
  359. <option value="threewayvalve_input">入料三通閥</option>
  360. <option value="diskvalve">蝴蝶閥</option>
  361. <option value="solenoid_disinfect">桶內消毒電磁閥</option>
  362. <option value="solenoid_water_out">排水廢水電磁閥</option>
  363. <option value="motor">馬達</option>
  364. <option value="vacuum_pump">乾燥真空機</option>
  365. <option value="heater1">加熱器1</option>
  366. <option value="heater2">加熱器2</option>
  367. <option value="solenoid_outer_water">保溫夾層進水電磁閥</option>
  368. <option value="Warning_Light" selected>警示燈</option>
  369. </select>
  370. {% else %}
  371. <select id="sensors">
  372. <option value="vacuum" selected>真空吸料機</option>
  373. <option value="threewayvalve_input">入料三通閥</option>
  374. <option value="diskvalve">蝴蝶閥</option>
  375. <option value="solenoid_disinfect">桶內消毒電磁閥</option>
  376. <option value="solenoid_water_out">排水廢水電磁閥</option>
  377. <option value="motor">馬達</option>
  378. <option value="vacuum_pump">乾燥真空機</option>
  379. <option value="heater1">加熱器1</option>
  380. <option value="heater2">加熱器2</option>
  381. <option value="solenoid_outer_water">保溫夾層進水電磁閥</option>
  382. <option value="Warning_Light">警示燈</option>
  383. </select>
  384. {% endif %}
  385. </td>
  386. </tr>
  387. <tr>
  388. <td style="border:1px gray solid;">
  389. 時間間隔:
  390. <select name="time-interval" class="text-right">
  391. <option value="month">逐月</option>
  392. <option value="day">逐日</option>
  393. <option value="hour">逐時</option>
  394. </select>
  395. &nbsp;
  396. <!--
  397. 從&nbsp;
  398. <input type="datetime-local" name="sensor_starttime" id="sensor_starttime" value={{starttime}}>
  399. &nbsp;到&nbsp;
  400. <input type="datetime-local" name="sensor_endtime" id="sensor_endtime" value={{endtime}}>
  401. &nbsp;為止
  402. -->
  403. <span>從</span>
  404. <label for="querydate-start"></label><input id="querydate-start" type="date">
  405. <span>到</span>
  406. <label for="querydate-end"></label><input id="querydate-end" type="date">
  407. <span>為止</span>
  408. </td>
  409. </tr>
  410. <tr>
  411. <td style="border:1px gray solid;">
  412. 資料類型:
  413. <label><input type="checkbox" name="data-type" value="max">最大值</label>
  414. <label><input type="checkbox" name="data-type" value="avg">平均值</label>
  415. <label><input type="checkbox" name="data-type" value="min">最小值</label>
  416. <br>
  417. </td>
  418. </tr>
  419. <tr>
  420. <td style="border:1px gray solid;">
  421. <!--
  422. <button type="submit" name="charting">繪製圖表</button>
  423. <button type="submit" onclick="" id="btn_save_chart" style="display: none;">儲存圖表</button>
  424. -->
  425. <input type="button" class="btn btn-secondary" value="查詢" onclick="ShowInfo()">
  426. <input type="button" class="btn btn-secondary" value="匯出" onclick="downloadFile()">
  427. <script>
  428. function ShowInfo() {
  429. // 取得桶號、感測器名稱
  430. tid = document.getElementById("tank_num").value
  431. console.log('tid: ' + tid)
  432. sensor_name = document.getElementById("sensors").value
  433. console.log('sensor_name: ' + sensor_name)
  434. // 數據整理
  435. Echart(sensor_name, tid)
  436. // 顯示圖表
  437. };
  438. function downloadFile() {
  439. tid = document.getElementById("tank_num").value
  440. sensor_name = document.getElementById("sensors").value
  441. //藉型別陣列建構的 blob 來建立 URL
  442. let fileName = "ChartData_" + tid + "_" + sensor_name + ".csv";
  443. //"\ufeff"解決打開CSV中文亂碼問題
  444. const data = "\ufeff" + getData();
  445. let blob = new Blob([data], {
  446. type: 'text/csv,charset=UTF-8'
  447. });
  448. var href = URL.createObjectURL(blob);
  449. // 從 Blob 取出資料
  450. var link = document.createElement("a");
  451. document.body.appendChild(link);
  452. link.href = href;
  453. link.download = fileName;
  454. link.click();
  455. };
  456. //所有資料函數
  457. function getData() {
  458. var header = "日期," + data_name + "\n";
  459. var data = "";
  460. var length = all_datetime.length;
  461. for (var i = 0; i < length; i++) {
  462. data = data + all_datetime[i] + ',' + all_data[i] + '\n';
  463. };
  464. return header + data;
  465. };
  466. //最大最小平均資料函數
  467. function getData() {
  468. var header = data_name + "\n日期,";
  469. if (max_data) {
  470. console.log(max_data);
  471. header = header + "最大值,";
  472. };
  473. if (avg_data) {
  474. header = header + "平均值,";
  475. };
  476. if (min_data) {
  477. header = header + "最小值,";
  478. };
  479. header = header + "\n";
  480. var data = "";
  481. var length = xAxis_data.length;
  482. for (var i = 0; i < length; i++) {
  483. data = data + xAxis_data[i] + ',';
  484. if (max_data) {
  485. data = data + max_data[i] + ',';
  486. };
  487. if (avg_data) {
  488. data = data + avg_data[i] + ',';
  489. };
  490. if (min_data) {
  491. data = data + min_data[i] + ',';
  492. };
  493. data = data + '\n';
  494. };
  495. return header + data;
  496. };
  497. </script>
  498. </td>
  499. </tr>
  500. <tr>
  501. <td>
  502. <!--
  503. <img src={{ url }}>
  504. -->
  505. <div id="" class="show-info" style="text-align: center;">
  506. <center>
  507. <div class="show-chart" style="height: 420px; width: 100%; text-align: center;">
  508. 圖表
  509. </div>
  510. </center>
  511. </div>
  512. </td>
  513. </tr>
  514. </table>
  515. </div>
  516. </div>
  517. </div>
  518. </div>
  519. </div>
  520. </div>
  521. </div>
  522. {% endblock %}
  523. {% block script2 %}
  524. <script>
  525. var all_datetime = 0; // 所有資料時間 ?
  526. var all_data = 0; // 所有感測器數據 ?
  527. var data_name = 0; // 感測器名稱 // "溫溼度"
  528. var xAxis_data = 0; // x 軸資料
  529. var max_data = 0; //
  530. var min_data = 0; //
  531. var avg_data = 0; //
  532. function Echart(sensor_name, tid) {
  533. // Echart(sensor_name, tid)
  534. //將echarts圖形銷毀
  535. $(".show-chart").removeAttr("_echarts_instance_").empty();
  536. // Rita:sensor 與 data_name 重複
  537. // var sensor = evt.substring(2);
  538. if (!$("input[value=avg]").prop('checked') && !$("input[value=min]").prop('checked') && !$("input[value=max]").prop('checked')) {
  539. alert("請至少選擇一種資料類型!");
  540. return false;
  541. };
  542. if ($("#querydate-start").val() == '' || $("#querydate-end").val() == '') {
  543. alert("請選擇日期範圍!");
  544. return false;
  545. };
  546. //基於準備好的dom,初始化echarts例項
  547. var myChart = echarts.init(document.getElementsByClassName('show-chart')[0]); // class="col-10 show-chart"
  548. var date_start = $("#querydate-start").val();
  549. var date_end = $("#querydate-end").val();
  550. var avg = 0;
  551. var max = 0;
  552. var min = 0;
  553. var time_interval = $("select[name=time-interval]").val();
  554. var legend = new Array();
  555. var color = new Array();
  556. var series = new Array();
  557. if ($("input[value=max]").prop('checked')) {
  558. max = 1;
  559. legend.push("最大值");
  560. color.push("#1e88e5"); // 水藍色
  561. };
  562. if ($("input[value=avg]").prop('checked')) {
  563. avg = 1;
  564. legend.push("平均值");
  565. color.push("#43a047"); // 草綠色
  566. };
  567. if ($("input[value=min]").prop('checked')) {
  568. min = 1;
  569. legend.push("最小值");
  570. color.push("#e64a19"); // 橘紅色
  571. };
  572. var json = {
  573. 'tid': tid,
  574. 'sensor_name': sensor_name,
  575. 'avg': avg,
  576. 'max': max,
  577. 'min': min,
  578. 'time-interval': time_interval,
  579. 'date-start': date_start,
  580. 'date-end': date_end
  581. };
  582. console.log('json___' +
  583. 'tid: ' + tid +
  584. 'sensor_name: ' + sensor_name +
  585. 'avg: ' + avg +
  586. 'max: ' + max +
  587. 'min: ' + min +
  588. 'time-interval: ' + time_interval +
  589. 'date-start: ' + date_start +
  590. 'date-end: ' + date_end
  591. )
  592. $.get('/history_data_new', json, function (resText) {
  593. if (resText.max) {
  594. var max_series = {
  595. 'name': '最大值',
  596. 'type': 'scatter',
  597. 'data': resText.max.map(function (item) { return item[1]; }),
  598. 'itemStyle': { 'normal': { 'lineStyle': { 'color': '#1e88e5' } } },
  599. };
  600. series.push(max_series); // 把上面的 dict 加入 series array 內
  601. xAxis_data = resText.max.map(function (item) { return item[0]; });
  602. max_data = resText.max.map(function (item) { return item[1]; });
  603. };
  604. if (resText.avg) {
  605. var avg_series = { 'name': '平均值', 'type': 'scatter', 'data': resText.avg.map(function (item) { return item[1]; }), 'itemStyle': { 'normal': { 'lineStyle': { 'color': '#43a047' } } }, };
  606. series.push(avg_series);
  607. xAxis_data = resText.avg.map(function (item) { return item[0]; });
  608. console.log('xAxis_data' + xAxis_data) // 2021-07-09 10:00:00,2021-07-20 09:00:00,2021-07-22 15:00:00,2021-07-26 15:00:00,2021-07-26 16:00:00
  609. avg_data = resText.avg.map(function (item) { return item[1]; });
  610. console.log('avg_data' + avg_data) // 91.0,98.0,11.0,15.2,30.5
  611. };
  612. if (resText.min) {
  613. var min_series = { 'name': '最小值', 'type': 'scatter', 'data': resText.min.map(function (item) { return item[1]; }), 'itemStyle': { 'normal': { 'lineStyle': { 'color': '#e64a19' } } }, };
  614. series.push(min_series);
  615. xAxis_data = resText.min.map(function (item) { return item[0]; }); // all
  616. min_data = resText.min.map(function (item) { return item[1]; }); // min
  617. };
  618. //獲取日期內所有數據
  619. all_datetime = resText.all.map(function (item) { return item[0]; }); // all
  620. all_data = resText.all.map(function (item) { return item[1]; });
  621. //指定圖表的配置項和資料
  622. option = {
  623. title: {
  624. text: '', // 'Data History'
  625. left: '1%'
  626. },
  627. tooltip: {
  628. trigger: 'axis'
  629. },
  630. color: color,
  631. legend: {
  632. data: legend,
  633. },
  634. xAxis: {
  635. data: xAxis_data,
  636. },
  637. yAxis: {
  638. splitLine: {
  639. show: true,
  640. lineStyle: {
  641. color: ''
  642. }
  643. }
  644. },
  645. toolbox: {
  646. show: true,
  647. feature: {
  648. saveAsImage: {}
  649. }
  650. },
  651. dataZoom: [{
  652. startValue: '2021-01-01'
  653. }, {
  654. type: 'inside'
  655. }],
  656. series: series,
  657. /*
  658. series: [
  659. {
  660. name: '最大值',
  661. type: 'line',
  662. data: resText.max.map(function (item) {
  663. return item[1];
  664. }),
  665. itemStyle: {
  666. normal: {
  667. lineStyle: {
  668. color: '#1e88e5'
  669. }
  670. }
  671. },
  672. },
  673. {
  674. name: '平均值',
  675. type: 'line',
  676. data: [20.0, 20.0, 20.0, 20.0, 20.0, 20.0],
  677. itemStyle: {
  678. normal: {
  679. lineStyle: {
  680. color: '#43a047'
  681. }
  682. }
  683. },
  684. },
  685. {
  686. name: '最小值',
  687. type: 'line',
  688. data: [15.0, 15.0, 15.0, 15.0, 15.0, 15.0],
  689. itemStyle: {
  690. normal: {
  691. lineStyle: {
  692. color: '#e64a19'
  693. }
  694. }
  695. }
  696. },
  697. ]
  698. */
  699. };
  700. console.log('SHOW myChart')
  701. //使用剛指定的配置項和資料顯示圖表
  702. myChart.setOption(option);
  703. window.addEventListener('resize', myChart.resize);
  704. }, 'json');
  705. } // Echart(sensor_name, tid)
  706. </script>
  707. {% endblock %}