sensor_chart_F.html 38 KB

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