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>故障診斷</h1><table style="font-size:16px;" class="table"> <tr> <th>主軸分析 </th><th>軸承分析 </th><th>馬達分析 </th><th>齒輪分析 </th> </tr> <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. document.getElementById("channel").innerHTML=inner;
  139. }
  140. get_data();
  141. get_chart_data();
  142. // 三張圖表
  143. function get_chart_data(){
  144. var xhr = new XMLHttpRequest();
  145. var url = "channel_chart/dev001/ch01";
  146. obj="";
  147. xhr.open("GET",url);
  148. xhr.onload = function(){
  149. obj = JSON.parse(xhr.responseText);
  150. for(var i=0;i<obj.length;i++){
  151. var Data = {
  152. labels: ["9/18", "9/19", "9/20", "9/21", "9/22", "9/23", "9/24"], //顯示區間名稱
  153. datasets: [{
  154. label: obj[i].name, // tootip 出現的名稱
  155. lineTension: 0, // 曲線的彎度,設0 表示直線
  156. backgroundColor: "#ea464d",
  157. borderColor: "#ea464d",
  158. borderWidth: 3,
  159. data:obj[i].data, // 資料
  160. fill: false, // 是否填滿色彩
  161. },]
  162. };
  163. var ctx = document.getElementById(obj[i].name).getContext("2d");
  164. drawLineCanvas(ctx,Data);
  165. }
  166. };
  167. xhr.send();
  168. }
  169. // var lineChartData = {
  170. // labels: ["9/18", "9/19", "9/20", "9/21", "9/22", "9/23", "9/24"], //顯示區間名稱
  171. // datasets: [{
  172. // label: '未曾使用', // tootip 出現的名稱
  173. // lineTension: 0, // 曲線的彎度,設0 表示直線
  174. // backgroundColor: "#ea464d",
  175. // borderColor: "#ea464d",
  176. // borderWidth: 5,
  177. // data: [10, 12, 15, 18, 22, 33, 50, 60, 130], // 資料
  178. // fill: false, // 是否填滿色彩
  179. // },]
  180. // };
  181. function drawLineCanvas(ctx,data) {
  182. window.myLine = new Chart(ctx, { //先建立一個 chart
  183. type: 'line', // 型態
  184. data: data,
  185. options: {
  186. responsive: true,
  187. legend: { //是否要顯示圖示
  188. display: true,
  189. },
  190. tooltips: { //是否要顯示 tooltip
  191. enabled: true
  192. },
  193. scales: { //是否要顯示 x、y 軸
  194. xAxes: [{
  195. display: true
  196. }],
  197. yAxes: [{
  198. display: true,
  199. }]
  200. },
  201. }
  202. });
  203. };
  204. function drawLineCanvas2(ctx,data) {
  205. window.myLine = new Chart(ctx, { //第二個 chart
  206. type: 'line', // 型態
  207. data: data,
  208. options: {
  209. responsive: true,
  210. legend: { //是否要顯示圖示
  211. display: true,
  212. },
  213. tooltips: { //是否要顯示 tooltip
  214. enabled: true
  215. },
  216. elements:{
  217. point:{
  218. radius:0
  219. }
  220. },
  221. scales: { //是否要顯示 x、y 軸
  222. xAxes: [{
  223. display: true,
  224. }],
  225. yAxes: [{
  226. display: true,
  227. ticks:{
  228. beginAtZero:true,
  229. stepSize:0.1,
  230. max:0.6,
  231. }
  232. }]
  233. },
  234. }
  235. });
  236. };
  237. function drawLineCanvas(ctx,data) {
  238. window.myLine = new Chart(ctx, { //先建立一個 chart
  239. type: 'line', // 型態
  240. data: data,
  241. options: {
  242. responsive: true,
  243. legend: { //是否要顯示圖示
  244. display: true,
  245. },
  246. tooltips: { //是否要顯示 tooltip
  247. enabled: true
  248. },
  249. scales: { //是否要顯示 x、y 軸
  250. xAxes: [{
  251. display: true
  252. }],
  253. yAxes: [{
  254. display: true,
  255. }]
  256. },
  257. }
  258. });
  259. };
  260. // window.onload = function () {
  261. // var ctx = document.getElementById("canvas").getContext("2d");
  262. // drawLineCanvas(ctx,lineChartData);
  263. // };
  264. get_predict();
  265. // 第四張
  266. function get_predict(){
  267. var xhr = new XMLHttpRequest();
  268. var url = "channel_predict/dev001/ch01";
  269. obj3="";
  270. xhr.open("GET",url);
  271. xhr.onload = function(){
  272. obj3 = JSON.parse(xhr.responseText);
  273. labels = new Array();
  274. for(var i=0;i<obj3.data.length;i++){
  275. labels.push(i);
  276. }
  277. var Data = {
  278. labels: labels, //顯示區間名稱
  279. datasets: [{
  280. label: "predict", // tootip 出現的名稱
  281. lineTension: 0, // 曲線的彎度,設0 表示直線
  282. backgroundColor: "#ea464d",
  283. borderColor: "#ea464d",
  284. borderWidth: 3,
  285. data:obj3.data, // 資料
  286. fill: false, // 是否填滿色彩
  287. },]
  288. };
  289. var ctx = document.getElementById("channel_predict").getContext("2d");
  290. drawLineCanvas(ctx,Data);
  291. };
  292. xhr.send();
  293. }
  294. // 第五張
  295. get_frequency();
  296. function get_frequency(){
  297. var xhr = new XMLHttpRequest();
  298. var url = "channel_frequency/dev001/ch01";
  299. obj4="";
  300. xhr.open("GET",url);
  301. console.log(obj4.value)
  302. xhr.onload = function(){
  303. obj4 = JSON.parse(xhr.responseText);
  304. var Data = {
  305. labels: obj4.Hz, //顯示區間名稱
  306. datasets: [{
  307. label: "frequency", // tootip 出現的名稱
  308. lineTension: 0, // 曲線的彎度,設0 表示直線
  309. backgroundColor: "#ea464d",
  310. borderColor: "#ea464d",
  311. borderWidth: 2,
  312. data:obj4.value, // 資料
  313. fill: false, // 是否填滿色彩
  314. },]
  315. };
  316. var ctx = document.getElementById("channel_frequency").getContext("2d");
  317. drawLineCanvas2(ctx,Data);
  318. };
  319. xhr.send();
  320. }