channel.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  1. obj="";
  2. obj2 = "";
  3. get_org();
  4. function get_org(){
  5. var xhr = new XMLHttpRequest();
  6. var url = "/org";
  7. xhr.open("GET",url);
  8. xhr.onload = function(){
  9. obj = JSON.parse(xhr.responseText);
  10. //insertHTML();
  11. start();
  12. onChangeColumn1();
  13. onChangeColumn2();
  14. onChangeColumn3();
  15. click_button();
  16. };
  17. xhr.send();
  18. }
  19. function insertHTML2(data){
  20. //aria.innerHTML=data[0].tower_name;
  21. var inner='';
  22. for(var i=0;i<data.length;i++){
  23. inner+='<option value="'+data[i].tower_name+'">'+data[i].tower_name+'</option>';
  24. }
  25. document.getElementById("tower").innerHTML=inner;
  26. }
  27. function click_button() {
  28. //alert("click");
  29. companySelect=document.getElementById("company-list");
  30. factorySelect=document.getElementById("factory-list");
  31. departmentSelect=document.getElementById("department-list");
  32. towerGroupSelect=document.getElementById("towerGroup-list");
  33. if(companySelect.value!=0 && factorySelect.value!=0 && departmentSelect.value!=0 && towerGroupSelect.value!=0){
  34. var url2 = "tower/?company="+ companySelect.value + "&factory=" + factorySelect.value + "&department=" +departmentSelect.value + "&towerGroup=" +towerGroupSelect.value ;
  35. var xhr2 = new XMLHttpRequest();
  36. xhr2.open("GET",url2);
  37. xhr2.onload = function(){
  38. obj2 = JSON.parse(xhr2.responseText);
  39. insertHTML2(obj2);
  40. console.log(obj2);
  41. };
  42. xhr2.send();
  43. }
  44. }
  45. function start(){
  46. companySelect=document.getElementById("company-list");
  47. factorySelect=document.getElementById("factory-list");
  48. departmentSelect=document.getElementById("department-list");
  49. towerGroupSelect=document.getElementById("towerGroup-list");
  50. var inner='';
  51. var company_arr = new Array();
  52. for(var i=0;i<obj.length;i++){
  53. if(company_arr.indexOf(obj[i].company)==-1 && obj[i].able==1){
  54. inner=inner+'<option value="'+obj[i].company+'">公司'+obj[i].company+'</option>';
  55. company_arr.push(obj[i].company);
  56. }
  57. }
  58. //innerHTML 賦值inner給這element屬性
  59. companySelect.innerHTML=inner;
  60. }
  61. //製造一個字串,以html的語法填入院的陣列
  62. function onChangeColumn1() {
  63. companySelect=document.getElementById("company-list");
  64. factorySelect=document.getElementById("factory-list");
  65. departmentSelect=document.getElementById("department-list");
  66. towerGroupSelect=document.getElementById("towerGroup-list");
  67. factorySelect.innerHTML='';
  68. let factory_arr = new Array();
  69. let factory_inner = '';
  70. for(var i=0;i<obj.length;i++){
  71. if( companySelect.value == obj[i].company){
  72. if(factory_arr.indexOf(obj[i].factory)==-1 && obj[i].able==1){
  73. factory_inner=factory_inner+'<option value="'+obj[i].factory+'">廠區'+obj[i].factory+'</option>';
  74. factory_arr.push(obj[i].factory);
  75. }
  76. }
  77. //alert(companySelect.value);
  78. }
  79. factorySelect.innerHTML=factory_inner;
  80. }
  81. function onChangeColumn2() {
  82. companySelect=document.getElementById("company-list");
  83. factorySelect=document.getElementById("factory-list");
  84. departmentSelect=document.getElementById("department-list");
  85. towerGroupSelect=document.getElementById("towerGroup-list");
  86. departmentSelect.innerHTML='';
  87. let department_arr = new Array();
  88. let department_inner = '';
  89. for(var i=0;i<obj.length;i++){
  90. if( companySelect.value == obj[i].company && factorySelect.value == obj[i].factory){
  91. if(department_arr.indexOf(obj[i].department)==-1 && obj[i].able==1){
  92. department_inner=department_inner+'<option value="'+obj[i].department+'">課'+obj[i].department+'</option>';
  93. department_arr.push(obj[i].department);
  94. }
  95. }
  96. }
  97. document.getElementById("department-list").innerHTML=department_inner;
  98. }
  99. function onChangeColumn3() {
  100. companySelect=document.getElementById("company-list");
  101. factorySelect=document.getElementById("factory-list");
  102. departmentSelect=document.getElementById("department-list");
  103. towerGroupSelect=document.getElementById("towerGroup-list");
  104. towerGroupSelect.innerHTML='';
  105. let towerGroup_inner = '';
  106. for(var i=0;i<obj.length;i++){
  107. if( companySelect.value == obj[i].company && factorySelect.value == obj[i].factory && departmentSelect.value == obj[i].department){
  108. if( obj[i].able==1){
  109. for(var ii=0;ii<obj[i].group.length;ii++){
  110. towerGroup_inner=towerGroup_inner+'<option value="'+obj[i].group[ii]+'">機組'+obj[i].group[ii]+'</option>';
  111. }
  112. }
  113. }
  114. }
  115. document.getElementById("towerGroup-list").innerHTML= towerGroup_inner;
  116. }
  117. function get_data(){
  118. var xhr = new XMLHttpRequest();
  119. var url = "channel/dev001/ch01";
  120. obj3="";
  121. xhr.open("GET",url);
  122. xhr.onload = function(){
  123. obj3 = JSON.parse(xhr.responseText);
  124. insertHTML(obj3);
  125. console.log(obj3);
  126. };
  127. xhr.send();
  128. }
  129. function insertHTML(data){
  130. console.log(data);
  131. //aria.innerHTML=data[0].tower_name;
  132. var inner='<h1 style="color:#002e86;">故障診斷</h1><div style="padding:15px;"><table style="font-size: 16px; border-color:#4c6caa; border-top:1px solid #4c6caa;" class="table text-center"><thead style="background:#e4f8ff; color:#4c6caa;"><tr><th class="border-0">主軸分析 </th><th class="border-0">軸承分析 </th><th class="border-0">馬達分析 </th><th class="border-0">齒輪分析</th></tr></thead><tr>';
  133. inner+='<td><span style="color: #078B07;">正常</span> 不平衡 '+data.DW_Unbalance+'</td><td><span style="color: #078B07;">正常</span> 油膜旋震 '+data.DW_Whirl+'</td><td><span style="color: #078B07;">正常</span> 氣隙不均 '+data.DW_AirGap+'</td><td><span style="color: #078B07;">正常</span> 齒輪不對中 '+data.DW_GMisalignment+'</td></tr><tr>';
  134. inner+='<td><span style="color: #078B07;">正常</span> 軸彎曲 '+data.DW_Unbalance+'</td><td><span style="color: #078B07;">正常</span> 油膜晃蕩 '+data.DW_Whirl+'</td><td><span style="color: #078B07;">正常</span> 轉子條斷裂 '+data.DW_AirGap+'</td><td><span style="color: #078B07;">正常</span> 齒輪斷齒 '+data.DW_GMisalignment+'</td></tr><tr>';
  135. inner+='<td><span style="color: #078B07;">正常</span> 不對中 '+data.DW_Unbalance+'</td><td><span style="color: #078B07;">正常</span> 內還損傷 '+data.DW_Whirl+'</td><td><span style="color: #078B07;">正常</span> 相位問題 '+data.DW_AirGap+'</td><td><span style="color: #078B07;">正常</span> 齒輪磨損 '+data.DW_GMisalignment+'</td></tr><tr>';
  136. inner+='<td><span style="color: #078B07;">正常</span> 鬆動 '+data.DW_Unbalance+'</td><td><span style="color: #078B07;">正常</span> 外環損傷 '+data.DW_Whirl+'</td><td></td><td><span style="color: #078B07;">正常</span> 齒輪彎曲 '+data.DW_GMisalignment+'</td></tr><tr>';
  137. inner+='<td> </td><td>正常 滾珠損傷 '+data.DW_Whirl+'</td><td></td><td>正常 齒輪偏心 '+data.DW_GMisalignment+'</td></tr><tr>';
  138. inner+='</div>'
  139. document.getElementById("channel").innerHTML=inner;
  140. }
  141. get_data();
  142. get_chart_data();
  143. // 三張圖表
  144. function get_chart_data(){
  145. var xhr = new XMLHttpRequest();
  146. var url = "channel_chart/dev001/ch01";
  147. obj="";
  148. xhr.open("GET",url);
  149. xhr.onload = function(){
  150. obj = JSON.parse(xhr.responseText);
  151. for(var i=0;i<obj.length;i++){
  152. var Data = {
  153. labels: ["9/18", "9/19", "9/20", "9/21", "9/22", "9/23", "9/24"], //顯示區間名稱
  154. datasets: [{
  155. label: obj[i].name, // tootip 出現的名稱
  156. lineTension: 0, // 曲線的彎度,設0 表示直線
  157. backgroundColor: "#ea464d",
  158. borderColor: "#ea464d",
  159. borderWidth: 3,
  160. data:obj[i].data, // 資料
  161. fill: false, // 是否填滿色彩
  162. },]
  163. };
  164. var ctx = document.getElementById(obj[i].name).getContext("2d");
  165. drawLineCanvas(ctx,Data);
  166. }
  167. };
  168. xhr.send();
  169. }
  170. // var lineChartData = {
  171. // labels: ["9/18", "9/19", "9/20", "9/21", "9/22", "9/23", "9/24"], //顯示區間名稱
  172. // datasets: [{
  173. // label: '未曾使用', // tootip 出現的名稱
  174. // lineTension: 0, // 曲線的彎度,設0 表示直線
  175. // backgroundColor: "#ea464d",
  176. // borderColor: "#ea464d",
  177. // borderWidth: 5,
  178. // data: [10, 12, 15, 18, 22, 33, 50, 60, 130], // 資料
  179. // fill: false, // 是否填滿色彩
  180. // },]
  181. // };
  182. function drawLineCanvas(ctx,data) {
  183. window.myLine = new Chart(ctx, { //先建立一個 chart
  184. type: 'line', // 型態
  185. data: data,
  186. options: {
  187. responsive: true,
  188. legend: { //是否要顯示圖示
  189. display: true,
  190. },
  191. tooltips: { //是否要顯示 tooltip
  192. enabled: true
  193. },
  194. scales: { //是否要顯示 x、y 軸
  195. xAxes: [{
  196. display: true
  197. }],
  198. yAxes: [{
  199. display: true,
  200. }]
  201. },
  202. }
  203. });
  204. };
  205. function drawLineCanvas2(ctx,data) {
  206. window.myLine = new Chart(ctx, { //第二個 chart
  207. type: 'line', // 型態
  208. data: data,
  209. options: {
  210. responsive: true,
  211. legend: { //是否要顯示圖示
  212. display: true,
  213. },
  214. tooltips: { //是否要顯示 tooltip
  215. enabled: true
  216. },
  217. elements:{
  218. point:{
  219. radius:0
  220. }
  221. },
  222. scales: { //是否要顯示 x、y 軸
  223. xAxes: [{
  224. display: true,
  225. }],
  226. yAxes: [{
  227. display: true,
  228. ticks:{
  229. beginAtZero:true,
  230. stepSize:0.1,
  231. max:0.6,
  232. }
  233. }]
  234. },
  235. }
  236. });
  237. };
  238. function drawLineCanvas(ctx,data) {
  239. window.myLine = new Chart(ctx, { //先建立一個 chart
  240. type: 'line', // 型態
  241. data: data,
  242. options: {
  243. responsive: true,
  244. legend: { //是否要顯示圖示
  245. display: true,
  246. },
  247. tooltips: { //是否要顯示 tooltip
  248. enabled: true
  249. },
  250. scales: { //是否要顯示 x、y 軸
  251. xAxes: [{
  252. display: true
  253. }],
  254. yAxes: [{
  255. display: true,
  256. }]
  257. },
  258. }
  259. });
  260. };
  261. // window.onload = function () {
  262. // var ctx = document.getElementById("canvas").getContext("2d");
  263. // drawLineCanvas(ctx,lineChartData);
  264. // };
  265. get_predict();
  266. // 第四張
  267. function get_predict(){
  268. var xhr = new XMLHttpRequest();
  269. var url = "channel_predict/dev001/ch01";
  270. obj3="";
  271. xhr.open("GET",url);
  272. xhr.onload = function(){
  273. obj3 = JSON.parse(xhr.responseText);
  274. labels = new Array();
  275. for(var i=0;i<obj3.data.length;i++){
  276. labels.push(i);
  277. }
  278. var Data = {
  279. labels: labels, //顯示區間名稱
  280. datasets: [{
  281. label: "predict", // tootip 出現的名稱
  282. lineTension: 0, // 曲線的彎度,設0 表示直線
  283. backgroundColor: "#ea464d",
  284. borderColor: "#ea464d",
  285. borderWidth: 3,
  286. data:obj3.data, // 資料
  287. fill: false, // 是否填滿色彩
  288. },]
  289. };
  290. var ctx = document.getElementById("channel_predict").getContext("2d");
  291. drawLineCanvas(ctx,Data);
  292. };
  293. xhr.send();
  294. }
  295. // 第五張
  296. get_frequency();
  297. function get_frequency(){
  298. var xhr = new XMLHttpRequest();
  299. var url = "channel_frequency/dev001/ch01";
  300. obj4="";
  301. xhr.open("GET",url);
  302. console.log(obj4.value)
  303. xhr.onload = function(){
  304. obj4 = JSON.parse(xhr.responseText);
  305. var Data = {
  306. labels: obj4.Hz, //顯示區間名稱
  307. datasets: [{
  308. label: "frequency", // tootip 出現的名稱
  309. lineTension: 0, // 曲線的彎度,設0 表示直線
  310. backgroundColor: "#ea464d",
  311. borderColor: "#ea464d",
  312. borderWidth: 2,
  313. data:obj4.value, // 資料
  314. fill: false, // 是否填滿色彩
  315. },]
  316. };
  317. var ctx = document.getElementById("channel_frequency").getContext("2d");
  318. drawLineCanvas2(ctx,Data);
  319. };
  320. xhr.send();
  321. }