actuator_chart_C.html 40 KB

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