Chart.cshtml 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713
  1. @*
  2. For more information on enabling MVC for empty projects, visit http://go.microsoft.com/fwlink/?LinkID=397860
  3. *@
  4. @{
  5. Layout = null;
  6. }
  7. @using Applications.UniversalApi_WebConsole_App.Models.OnlineMonitor
  8. @model Applications.UniversalApi_WebConsole_App.Models.OnlineMonitor.OnlineMonitorInfo
  9. @{
  10. int screenWidth = 1280;
  11. int mainviewHeight = 570;
  12. int tableMargin = 10;
  13. int tableWidth = screenWidth - tableMargin - 63;
  14. int tableHeight = mainviewHeight - tableMargin;
  15. int scatterOrTableImgWidth = 66;
  16. int scatterOrTableImgHeight = 72;
  17. int queryViewWidth = 207;
  18. int colCount = 7;
  19. int maximumAL = 2;//should get from configuration
  20. int minimumAL = 1;//shold get from configuration
  21. string warningPointColor = "rgba(255, 255, 0,1)";//as prs said it should be yellow
  22. string maximumALLineColor = "rgba(255, 0, 0, 1)";//red
  23. string minimumALLineColor = "rgba(0, 0, 255, 1)";//blue
  24. string normalPointColor = "rgba(0, 0, 255, 1)";//blue
  25. int headRightHeight = 44;
  26. int queryImgWidth = 61;
  27. int queryImgTop = 0;
  28. //int queryImgTop = headRightHeight + 10;
  29. }
  30. <script>
  31. function DisplayQueryView() {
  32. var queryView = document.getElementById("Query_view");
  33. var queryButton = document.getElementById("Query_button_chartTable");
  34. if (queryButton != null && queryButton.style.visibility === "visible") {
  35. queryButton.style.visibility = "hidden";
  36. queryButton.style.display = "none";
  37. }
  38. if (queryView != null && queryView.style.visibility === "hidden") {
  39. queryView.style.visibility = "visible";
  40. queryView.style.display = "";
  41. }
  42. }
  43. function HideQueryView() {
  44. var queryView = document.getElementById("Query_view");
  45. var queryButton = document.getElementById("Query_button_chartTable");
  46. if (queryButton != null && queryButton.style.visibility === "hidden") {
  47. queryButton.style.visibility = "visible";
  48. queryButton.style.display = "";
  49. }
  50. if (queryView != null && queryView.style.visibility === "visible") {
  51. queryView.style.visibility = "hidden";
  52. queryView.style.display = "none";
  53. }
  54. }
  55. function Pad(num, n) {
  56. var len = num.toString().length;
  57. while (len < n) {
  58. num = "0" + num;
  59. len++;
  60. }
  61. return num;
  62. }
  63. function ClearAndReSetUpTableData(datas) {
  64. if (datas == null) {
  65. console.log("response data is null for chart table");
  66. return;
  67. }
  68. var chartTable = document.getElementById("Chart_table");
  69. if (chartTable == null) {
  70. console.log("chart table is not created");
  71. return;
  72. }
  73. var originalTableRows = chartTable.rows.length;
  74. datas.forEach(function (d) {
  75. var r = chartTable.insertRow(chartTable.rows.length);
  76. //var c1 = r.insertCell(r.cells.length);
  77. //c1.innerHTML = d.DataCollectorNozzleNumber;
  78. var c1 = r.insertCell(r.cells.length);
  79. c1.innerHTML = d.SiteLevelNozzleId;
  80. var c2 = r.insertCell(r.cells.length);
  81. c2.innerHTML = d.SensorId;
  82. var c3 = r.insertCell(r.cells.length);
  83. c3.innerHTML = new Date(d.FuellingStartTime).getFullYear() + "-" + Pad(new Date(d.FuellingStartTime).getMonth() + 1, 2) + "-" + Pad(new Date(d.FuellingStartTime).getDate(), 2);
  84. var c4 = r.insertCell(r.cells.length);
  85. c4.innerHTML = (new Date(d.FuellingEndTime) - new Date(d.FuellingStartTime)) / 1000;
  86. var c5 = r.insertCell(r.cells.length);
  87. c5.innerHTML = d.VaporLiquidRatio;
  88. var c6 = r.insertCell(r.cells.length);
  89. c6.innerHTML = d.VaporVolume;
  90. var c7 = r.insertCell(r.cells.length);
  91. c7.innerHTML = d.LiquidVolume;
  92. });
  93. //insert an empty row, otherwise the style of the table will be changed
  94. if (datas.length === 0) {
  95. var r = chartTable.insertRow(chartTable.rows.length);
  96. var c1 = r.insertCell(r.cells.length);
  97. c1.innerHTML = "";
  98. var c2 = r.insertCell(r.cells.length);
  99. c2.innerHTML = "";
  100. var c3 = r.insertCell(r.cells.length);
  101. c3.innerHTML = "";
  102. var c4 = r.insertCell(r.cells.length);
  103. c4.innerHTML = "";
  104. var c5 = r.insertCell(r.cells.length);
  105. c5.innerHTML = "";
  106. var c6 = r.insertCell(r.cells.length);
  107. c6.innerHTML = "";
  108. var c7 = r.insertCell(r.cells.length);
  109. c7.innerHTML = "";
  110. }
  111. for (var count = 1; count < originalTableRows; count++) {
  112. chartTable.deleteRow(1);
  113. };
  114. }
  115. //更新报警列表:筛选条件改变、用户初始进入该页面
  116. function UpdateWarningHistoryTable(datas) {
  117. if (datas == null) {
  118. console.log("Warning History response data is null");
  119. return;
  120. }
  121. var warningHistoryTable = document.getElementById("Chart_warning_history_table");
  122. if (warningHistoryTable == null) {
  123. console.log("Warning history table is null");
  124. return;
  125. }
  126. var originalTableRows = warningHistoryTable.rows.length;
  127. datas.forEach(function (d) {
  128. var r = warningHistoryTable.insertRow(warningHistoryTable.rows.length);
  129. var c1 = r.insertCell(r.cells.length);
  130. c1.style.width = '20%';
  131. c1.innerHTML = d.AlarmTime;
  132. var c2 = r.insertCell(r.cells.length);
  133. c2.style.width = '20%';
  134. c2.innerHTML = d.AlarmDescription;
  135. var c3 = r.insertCell(r.cells.length);
  136. c3.style.width = '60%';
  137. c3.style.textAlign = 'left';
  138. c3.innerHTML = d.AlarmDetails;
  139. });
  140. //insert a empty row to keep the table body style when there's no data in response message
  141. if (datas.length === 0) {
  142. var r = warningHistoryTable.insertRow(warningHistoryTable.rows.length);
  143. var c1 = r.insertCell(r.cells.length);
  144. c1.style.width = '20%';
  145. c1.innerHTML = "";
  146. var c2 = r.insertCell(r.cells.length);
  147. c2.style.width = '20%';
  148. c2.innerHTML = "";
  149. var c3 = r.insertCell(r.cells.length);
  150. c3.style.width = '60%';
  151. c3.style.textAlign = 'left';
  152. c3.innerHTML = "";
  153. }
  154. for (var count = 1; count < originalTableRows; count++) {
  155. warningHistoryTable.deleteRow(1);
  156. }
  157. }
  158. //放大镜图标及主窗口显示曲线图、表格还是报警历史的切换
  159. function reloadQueryImag(queryImgId) {
  160. document.getElementById(queryImgId).style.visibility = "hidden";
  161. var scatterChartDiv = document.getElementById("Chart_scatter_div");
  162. var tableChartDiv = document.getElementById("Chart_table_div");
  163. var waningTableDiv = document.getElementById("Chart_warning_div");
  164. if (queryImgId === "Chart_query_scatter2") {
  165. document.getElementById("Chart_query_warning").style.visibility = "visible";
  166. if (scatterChartDiv != null && scatterChartDiv.style.visibility === "hidden") {
  167. scatterChartDiv.style.visibility = "visible";
  168. }
  169. if (tableChartDiv != null && tableChartDiv.style.visibility === "visible") {
  170. tableChartDiv.style.visibility = "hidden";
  171. }
  172. if (waningTableDiv != null && waningTableDiv.style.visibility === "visible") {
  173. waningTableDiv.style.visibility = "hidden";
  174. }
  175. } else if (queryImgId === "Chart_query_scatter1") {
  176. document.getElementById("Chart_query_table").style.visibility = "visible";
  177. if (tableChartDiv != null && tableChartDiv.style.visibility === "visible") {
  178. tableChartDiv.style.visibility = "hidden";
  179. }
  180. if (waningTableDiv != null && waningTableDiv.style.visibility === "visible") {
  181. waningTableDiv.style.visibility = "hidden";
  182. }
  183. if (scatterChartDiv != null && scatterChartDiv.style.visibility === "hidden") {
  184. scatterChartDiv.style.visibility = "visible";
  185. }
  186. document.getElementById("Chart_query_table").style.visibility = "visible";
  187. } else if (queryImgId === "Chart_query_table") {
  188. document.getElementById("Chart_query_scatter2").style.visibility = "hidden";
  189. document.getElementById("Chart_query_scatter1").style.visibility = "visible";
  190. document.getElementById("Chart_query_warning").style.visibility = "visible";
  191. if (scatterChartDiv != null && scatterChartDiv.style.visibility === "visible") {
  192. scatterChartDiv.style.visibility = "hidden";
  193. }
  194. if (tableChartDiv != null && tableChartDiv.style.visibility === "hidden") {
  195. tableChartDiv.style.visibility = "visible";
  196. }
  197. if (waningTableDiv != null && waningTableDiv.style.visibility === "visible") {
  198. waningTableDiv.style.visibility = "hidden";
  199. }
  200. } else if (queryImgId === "Chart_query_warning") {
  201. document.getElementById("Chart_query_scatter1").style.visibility = "hidden";
  202. document.getElementById("Chart_query_scatter2").style.visibility = "visible";
  203. document.getElementById("Chart_query_table").style.visibility = "visible";
  204. if (scatterChartDiv != null && scatterChartDiv.style.visibility === "visible") {
  205. scatterChartDiv.style.visibility = "hidden";
  206. }
  207. if (tableChartDiv != null && tableChartDiv.style.visibility === "visible") {
  208. tableChartDiv.style.visibility = "hidden";
  209. }
  210. if (waningTableDiv != null && waningTableDiv.style.visibility === "hidden") {
  211. waningTableDiv.style.visibility = "visible";
  212. }
  213. }
  214. }
  215. </script>
  216. <div id="charts_table" style="position: relative; width: (@screenWidth)px; height: (@mainviewHeight)px">
  217. <style type="text/css">
  218. .table{
  219. border-collapse:collapse;
  220. }
  221. .table tr td{
  222. /*border-bottom: 1px solid#00bfff;
  223. border-left: 1px solid #00bfff;*/
  224. color: #000000;
  225. font-size: 22px;
  226. /*padding:5px 8px;*/
  227. text-align: center;
  228. }
  229. .table>tbody>tr,.table>thead{
  230. display: table;
  231. width: 100%;
  232. height:@(tableHeight/11)px;
  233. table-layout:fixed;
  234. }
  235. .table>tbody{
  236. height:@(tableHeight-tableHeight/11)px;
  237. overflow: hidden;
  238. display: block;
  239. overflow: hidden;
  240. overflow-y:auto;
  241. }
  242. </style>
  243. <div id="Chart_table_div" onclick="HideQueryView()" style="position: relative; margin-left: @(tableMargin)px; top: @(tableMargin)px;width:@(tableWidth)px; height:@(tableHeight)px;visibility:visible;">
  244. <table id="Chart_table" class="table" style="width: 100%;">
  245. @{
  246. int colwidth = (100 / 7) * (tableWidth);
  247. }
  248. <thead>
  249. <tr style="font-weight: bold">
  250. <td style="width:(@colwidth)px;">油站枪号</td>
  251. <td style="width:(@colwidth)px;">传感器号</td>
  252. <td style="width:(@colwidth)px;">时间</td>
  253. <td style="width:(@colwidth)px;">加油时间(s)</td>
  254. <td style="width:(@colwidth)px;">A/L(%)</td>
  255. <td style="width:(@colwidth)px;">油气流量(L)</td>
  256. <td style="width:(@colwidth)px;">燃油流量(L)</td>
  257. </tr>
  258. </thead>
  259. <tbody>
  260. @*@foreach (var t in Model.Transactions)
  261. {*@
  262. <tr>
  263. <td style="width: (@colwidth)px;"></td>
  264. <td style="width: (@colwidth)px;"></td>
  265. <td style="width: (@colwidth)px;"></td>
  266. <td style="width: (@colwidth)px;"></td>
  267. <td style="width: (@colwidth)px;"></td>
  268. <td style="width: (@colwidth)px;"></td>
  269. <td style="width: (@colwidth)px;"></td>
  270. </tr>
  271. @*}*@
  272. </tbody>
  273. </table>
  274. <script>
  275. // ClearAndReSetUpTableData(chartTableSamleData.data);
  276. </script>
  277. </div>
  278. <div id="Chart_scatter_div" onclick="HideQueryView()" style="position: absolute; left: @(tableMargin)px; top: @(tableMargin)px; width: @(tableWidth)px; height: @(tableHeight)px;visibility: hidden;">
  279. <canvas id="Chart_scatter_canvas" style="width: 100%; height: 100%;">
  280. Your browser does not support the canvas element.
  281. </canvas>
  282. </div>
  283. <div id="Chart_warning_div" onclick="HideQueryView()" style="position: absolute; left: @(tableMargin)px; top: @(tableMargin)px; width: @(tableWidth)px; height: @(tableHeight)px; visibility: hidden;">
  284. <table id="Chart_warning_history_table" class="table" style="width: 100%;">
  285. <thead>
  286. <tr style="font-weight: bold">
  287. <td style="width: 20%;">警报时间</td>
  288. <td style="width: 20%;">警报类型</td>
  289. <td style="width: 60%;">警报说明</td>
  290. </tr>
  291. </thead>
  292. <tbody>
  293. <tr>
  294. <td style="width: 20%;"></td>
  295. <td style="width: 20%;"></td>
  296. <td style="width: 60%; text-align: left;"></td>
  297. </tr>
  298. </tbody>
  299. </table>
  300. </div>
  301. <div id="Query_view" style="position: absolute; left: @(screenWidth - queryViewWidth)px; top: 0px; width:@(queryViewWidth)px; font-weight: bold; background-image: url(/images/onlineMonitor/chartView/background_query.png); height: @(mainviewHeight)px; visibility: hidden;">
  302. @{
  303. int lableFontSize = 16;
  304. int queryFontSize = 20;
  305. string defaultDate = DateTime.Now.ToString("yyyy-MM-dd");
  306. }
  307. <span style="position: relative; display: inline-block; width: 100%; padding-bottom: 5px; font-size: 24px; text-align: center;">筛选查询</span>
  308. <span style="position: relative; display: inline-block; text-align: left; font-size: @(lableFontSize)px;">起始日期:</span>
  309. <input type="date" id="StartDate" value="@defaultDate" style="margin-left: 20px; width: @(queryViewWidth - 20)px; margin-right: 0px; border: 0px; background-image: inherit; font-size: @(queryFontSize)px;" />
  310. <span style="position: relative; display: inline-block; text-align: left; font-size: @(lableFontSize)px;">结束日期:</span>
  311. <input type="date" id="EndDate" value="@defaultDate" style="margin-left: 20px; width: @(queryViewWidth - 20)px; margin-right: 0px; border: 0px; background-image: inherit; font-size: @(queryFontSize)px;" />
  312. <span style="position: relative; display: inline-block; margin-top: 10px; text-align: left; font-size: @(lableFontSize)px;">油枪选择:</span>
  313. <br />
  314. <select id="Chart_table_Nozzles" style="margin-left: 20px; width: @(queryViewWidth - 20)px; margin-right: 0px; border: 0px; background-image: inherit; font-size: @(queryFontSize)px;"></select>
  315. <br>
  316. <span style="position: relative; display: inline-block; margin-top: 10px; text-align: left; font-size: @(lableFontSize)px;">查询条件:</span>
  317. <ul id="Chart_table_Criteria">
  318. @foreach (var f in Model.QueryInformation.OptionalCriteria)
  319. {
  320. var backgroundImag = (f == Criteria.气液比.ToString()) ? "url(/images/onlineMonitor/chartView/select.png)" : "none";
  321. <li id="Chart_table_Criteria_@f" onclick="CriterialSelect(this.id)" style="font-size: @(queryFontSize)px; padding: 2px; width: 137px; height: 32px; list-style-type: none; background-position-x: 0px; background-image: @backgroundImag; background-repeat: no-repeat; text-align: center;">@f</li>
  322. }
  323. </ul>
  324. <img id="Chart_query_scatter1" src="/images/onlineMonitor/chartView/scatter.png" onclick="DisplayChart(this.id)" style="position: absolute; left:20px; top: @(mainviewHeight - scatterOrTableImgHeight)px;">
  325. <img id="Chart_query_table" src="/images/onlineMonitor/chartView/table.png" onclick="DisplayChart(this.id)" style="position: absolute; left:20px; top: @(mainviewHeight - scatterOrTableImgHeight)px; visibility: hidden;">
  326. <img id="Chart_query_scatter2" src="/images/onlineMonitor/chartView/scatter.png" onclick="DisplayChart(this.id)" style="position: absolute; left:@(queryViewWidth-scatterOrTableImgWidth-20*2)px; top: @(mainviewHeight - scatterOrTableImgHeight)px; visibility: hidden;">
  327. <img id="Chart_query_warning" src="/images/onlineMonitor/chartView/alarm.png" onclick="DisplayChart(this.id)" style="position: absolute; left:@(queryViewWidth-scatterOrTableImgWidth-20*2)px; top: @(mainviewHeight - scatterOrTableImgHeight)px;">
  328. </div>
  329. </div>
  330. <img id="Query_button_chartTable" onclick="DisplayQueryView()" style="position: absolute; margin: 0px; top:@(queryImgTop)px; left: @(screenWidth - queryImgWidth)px; visibility: visible;" src="/images/onlineMonitor/chartView/query.png" />
  331. <script src="~/js/mqtt.min.js"></script>
  332. <script type="text/javascript">
  333. var hostname = 'localhost', //'192.168.1.2',
  334. port = 8384,
  335. clientId = 'mqttjs_' + (Math.random() * 1000000).toString(),
  336. timeout = 5000,
  337. keepAlive = 100,
  338. cleanSession = false,
  339. mqttVersion = 3,
  340. ssl = false;
  341. var warningValueMin = 1;
  342. var warningValueMax = 2;
  343. //var client = new Paho.MQTT.Client(hostname, port, clientId);
  344. //client.onConnectionLost = onConnectionLost;//绑定连接断开事件
  345. //client.onMessageArrived = onMessageArrived;//
  346. var options = {
  347. //mqtt客户端的id,这里面应该还可以加上其他参数,具体看官方文档
  348. clientId: 'mqttjs_' + (Math.random() * 1000000).toString(),
  349. //invocationContext: {
  350. // host: hostname,
  351. // port: port,
  352. // //path: client.path,
  353. // mqttVersion:mqttVersion,
  354. // clientId: clientId
  355. //},
  356. //mqttVersion:mqttVersion,
  357. timeout: timeout,
  358. //keepAliveInterval: keepAlive,
  359. //cleanSession: cleanSession,
  360. useSSL: false
  361. //onSuccess: onConnect,
  362. //onFailure: onError
  363. }
  364. //浏览器采用websocket协议,host主机地址为192.168.0.200,端口为9001,路径为/mqtt
  365. var client = mqtt.connect("@Model.mqttConnectionString", options); // you add a ws:// url here
  366. ////建立连接
  367. client.on('connect',
  368. function () {
  369. console.log("connected");
  370. client.subscribe('/sys/Vapor_Recovery_App/Application.VaporRecoveryApp.App/thing/service/GetConfigAsync_reply',
  371. function (err) {
  372. if (!err) {
  373. client.publish('/sys/Vapor_Recovery_App/Application.VaporRecoveryApp.App/thing/service/GetConfigAsync', 'Hello mqtt');
  374. } else {
  375. console.log("error exist during subscribe GetConfigAsync_reply");
  376. }
  377. });
  378. client.subscribe('/sys/Vapor_Recovery_App/Application.VaporRecoveryApp.App/thing/service/GetNozzlesData_reply',
  379. function (err) {
  380. if (!err) {
  381. client.publish('/sys/Vapor_Recovery_App/Application.VaporRecoveryApp.App/thing/service/GetNozzlesData', "Hello mqtt");
  382. };
  383. });
  384. //When the view was loaded, get the nozzleflow data as default information
  385. client.subscribe('/sys/Vapor_Recovery_App/Application.VaporRecoveryApp.App/thing/service/GetNozzlesFlowData_reply',
  386. function (err) {
  387. if (!err) {
  388. var currentDate = new Date(Date.now());
  389. var startTime = currentDate.getFullYear().toString() + "/" + Pad(currentDate.getMonth() + 1, 2) + "/" + Pad(currentDate.getDate(), 2) + " 00:00:00";
  390. var endTime = currentDate.getFullYear().toString() + "/" + Pad(currentDate.getMonth() + 1, 2) + "/" + Pad(currentDate.getDate(), 2) + " 23:59:59";
  391. var temp = {
  392. "Parameters": [
  393. { "Name": "nozzleid", "Value": "1" },
  394. { "Name": "starttime", "Value": startTime },
  395. { "Name": "endtime", "Value": endTime }
  396. ]
  397. };
  398. var message = JSON.stringify(temp);
  399. client.publish('/sys/Vapor_Recovery_App/Application.VaporRecoveryApp.App/thing/service/GetNozzlesFlowData', message);
  400. };
  401. });
  402. client.subscribe('/sys/Vapor_Recovery_App/Application.VaporRecoveryApp.App/thing/service/GetAlarmList_reply',
  403. function (err) {
  404. if (!err) {
  405. console.log("subscribe GetAlarmList_reply successfully");
  406. };
  407. });
  408. });
  409. //如果连接错误,打印错误
  410. client.on('error',
  411. function (err) {
  412. console.log("error happens, will close the client");
  413. client.end();
  414. });
  415. //如果client订阅主题成功,那么这里就是当接收到自己订阅主题的处理逻辑
  416. client.on('message',
  417. function (topic, message) {
  418. // message is Buffer,此处就是打印消息的具体内容
  419. console.log('-> ' + message.toString());
  420. var a = document.getElementById("testmqqt");
  421. if (a != null) a.innerHTML = topic;
  422. if (topic === "/sys/Vapor_Recovery_App/Application.VaporRecoveryApp.App/thing/service/GetConfigAsync_reply") {
  423. processConfigData(JSON.parse(message.toString()));
  424. return;
  425. }
  426. if (topic === "/sys/Vapor_Recovery_App/Application.VaporRecoveryApp.App/thing/service/GetNozzlesData_reply") {
  427. processNozzlesData(JSON.parse(message.toString()));
  428. return;
  429. }
  430. if (topic === '/sys/Vapor_Recovery_App/Application.VaporRecoveryApp.App/thing/service/GetNozzlesFlowData_reply') {
  431. if (document.getElementById("Chart_table_div") != null && document.getElementById("Chart_table_div").style.visibility === "visible") {
  432. ClearAndReSetUpTableData(JSON.parse(message.toString()));
  433. }
  434. else if (document.getElementById("Chart_scatter_div") != null && document.getElementById("Chart_scatter_div").style.visibility === "visible") {
  435. UpdateALScatterChart(JSON.parse(message.toString()));
  436. }
  437. return;
  438. }
  439. if (topic === "/sys/Vapor_Recovery_App/Application.VaporRecoveryApp.App/thing/service/GetAlarmList_reply") {
  440. UpdateWarningHistoryTable(JSON.parse(message.toString()));
  441. return;
  442. }
  443. });
  444. //得到最大最小警戒值,用做点状图中使用
  445. function processConfigData(message) {
  446. if (message != null && message.onlineWatchConfig != null) {
  447. warningValueMin = message.onlineWatchConfig.WarningValueMin;
  448. warningValueMax = message.onlineWatchConfig.WarningValueMax;
  449. }
  450. console.log("最小警戒值:" + warningValueMin + "最大警戒值:" + warningValueMax);
  451. }
  452. function processNozzlesData(message) {
  453. if (message != null && message.data != null) {
  454. if (document.getElementById("Chart_table_Nozzles") != null) {
  455. var nozzleSelect = document.getElementById("Chart_table_Nozzles");
  456. nozzleSelect.options.length = 0;
  457. message.data.forEach(function (d) {
  458. nozzleSelect.options.add(new Option(d.SiteLevelNozzleId + "号枪", d.SiteLevelNozzleId));
  459. });
  460. }
  461. }
  462. }
  463. //// 用户程序点击事件
  464. function Onmqtttest() {
  465. message = "message from browser with websocket"; // 消息内容
  466. //发布主题presence,消息内容为Hello mqtt,订阅与推送一样自发自收
  467. client.publish('/sys/Vapor_Recovery_App/Application.VaporRecoveryApp.App/thing/service/GetConfigAsync', 'Hello mqtt ' + message);
  468. var a = document.getElementById("testmqqt");
  469. if (a != null) a.innerHTML = message;
  470. }
  471. function DisplayChart(tabId) {
  472. reloadQueryImag(tabId);
  473. var startTime = document.getElementById("StartDate").value + " 00:00:00";
  474. var endTime = document.getElementById("EndDate").value + " 23:59:59";
  475. var nozzleNumber = encodeURI(document.getElementById("Chart_table_Nozzles").value);//.slice(0, 1);
  476. var temp = {
  477. "Parameters": [
  478. { "Name": "nozzleid", "Value": nozzleNumber },
  479. { "Name": "starttime", "Value": startTime },
  480. { "Name": "endtime", "Value": endTime }
  481. ]
  482. };
  483. var message = JSON.stringify(temp);
  484. //曲线查询
  485. if (tabId === "Chart_query_scatter1" || tabId === "Chart_query_scatter2" || tabId === "Chart_query_table") {
  486. if (client != null) {
  487. client.publish('/sys/Vapor_Recovery_App/Application.VaporRecoveryApp.App/thing/service/GetNozzlesFlowData', message);
  488. }
  489. } else if (tabId === "Chart_query_warning") {
  490. if (client != null) {
  491. client.publish('/sys/Vapor_Recovery_App/Application.VaporRecoveryApp.App/thing/service/GetAlarmList', message);
  492. }
  493. }
  494. HideQueryView();
  495. }
  496. function CriterialSelect(id) {
  497. var criterialList = document.getElementById("Chart_table_Criteria");
  498. //alert(id);
  499. if (criterialList != null && criterialList.getElementsByTagName("li") != null && criterialList.getElementsByTagName("li").length > 0) {
  500. var children = criterialList.getElementsByTagName("li");
  501. //alert(children.length);
  502. for (var i = 0; i < children.length; i++) {
  503. children[i].style.backgroundImage = "none";
  504. }
  505. }
  506. var selectItemStr = "";
  507. var selectItem = document.getElementById(id);
  508. if (selectItem != null) {
  509. selectItem.style.backgroundImage = "url(/images/onlineMonitor/chartView/select.png)";
  510. selectItemStr = selectItem.innerHTML;
  511. }
  512. var startTime = document.getElementById("StartDate").value + " 00:00:00";
  513. var endTime = document.getElementById("EndDate").value + " 23:59:59";
  514. var nozzleNumber = encodeURI(document.getElementById("Chart_table_Nozzles").value);//.slice(0, 1)
  515. var temp = {
  516. "Parameters": [
  517. { "Name": "nozzleid", "Value": nozzleNumber },
  518. { "Name": "starttime", "Value": startTime },
  519. { "Name": "endtime", "Value": endTime }
  520. ]
  521. };
  522. var message = JSON.stringify(temp);
  523. if ((document.getElementById("Chart_table_div") != null && document.getElementById("Chart_table_div").style.visibility === "visible") ||
  524. (document.getElementById("Chart_scatter_div") != null && document.getElementById("Chart_scatter_div").style.visibility === "visible")) {
  525. if (client != null) {
  526. client.publish('/sys/Vapor_Recovery_App/Application.VaporRecoveryApp.App/thing/service/GetNozzlesFlowData', message);
  527. }
  528. } else if (document.getElementById("Chart_warning_div") != null && document.getElementById("Chart_warning_div").style.visibility === "visible") {
  529. if (client != null) {
  530. client.publish('/sys/Vapor_Recovery_App/Application.VaporRecoveryApp.App/thing/service/GetAlarmList', message);
  531. }
  532. }
  533. HideQueryView();
  534. }
  535. </script>
  536. <script src="~/js/jquery-3.4.1.min.js"></script>
  537. <script src="~/js/Chart.bundle.js"></script>
  538. <script>
  539. var minimumScatterChartPoint = 10;
  540. var config_scatterChart = {
  541. type: 'scatter',
  542. data: {
  543. //lablels: [0, 0, 0],
  544. datasets: [
  545. {
  546. type: 'line',
  547. label: 'AL最大值',
  548. borderColor: '@maximumALLineColor',
  549. pointRadius: 0,
  550. fill: false,
  551. yAxisID: 'y-axis-1',
  552. borderWidth: 1
  553. //data: [0, 0, 0]
  554. }, {
  555. type: 'line',
  556. label: '汽液比最小值',
  557. borderColor: '@minimumALLineColor',
  558. pointRadius: 0,
  559. fill: false,
  560. yAxisID: 'y-axis-1',
  561. borderWidth: 1
  562. //data: [0, 0, 0]
  563. }, {
  564. type: 'scatter',
  565. label: '单笔交易汽液比',
  566. borderColor: ['rgba(255, 127, 0, 1)'],
  567. pointRadius: 2,
  568. //pointStyle:'crossRot',
  569. borderWidth: 1,
  570. fill: true,
  571. yAxisID: 'y-axis-1'
  572. //data: [0, 0, 0]
  573. }
  574. ]
  575. },
  576. options: {
  577. responsive: true,
  578. hoverMode: 'index',
  579. stacked: true,
  580. animation: {
  581. duration: 0 // general animation time
  582. },
  583. hover: {
  584. animationDuration: 0 // duration of animations when hovering an item
  585. },
  586. responsiveAnimationDuration: 0, // animation duration after a resize
  587. //title: {
  588. // display: true,
  589. // text: '汽液比散点图',
  590. // fontSize: 35,
  591. // fontColor: "#000"
  592. //},
  593. scales: {
  594. xAxes: [{
  595. type: 'time',
  596. distribution:'linear',
  597. time: {
  598. //stepSize: 2,
  599. displayFormats: {
  600. quarter: 'YYYY MMM D h:mm:ss'
  601. }
  602. },
  603. scaleLabel: {
  604. display: true,
  605. labelString: '时间'
  606. },
  607. ticks: {
  608. autoSkip: true,
  609. maxTicksLimit: 20
  610. }
  611. }],
  612. yAxes: [{
  613. type: 'linear', // only linear but allow scale type registration. This allows extensions to exist solely for log scale for instance
  614. display: true,
  615. position: 'left',
  616. id: 'y-axis-1',
  617. ticks: {
  618. beginAtZero: true,
  619. suggestedMax: 3,
  620. stepSize: 0.5
  621. },
  622. scaleLabel: {
  623. display: true,
  624. labelString: '汽液比'
  625. }
  626. }],
  627. elements: {
  628. line: {
  629. tension: 1 // disables bezier curves
  630. }
  631. }
  632. },
  633. tooltips: {
  634. mode: 'index',
  635. intersect: true
  636. }
  637. }
  638. };
  639. var ctx = document.getElementById('Chart_scatter_canvas');
  640. var alScatterChart = new Chart(ctx, config_scatterChart);
  641. function UpdateALScatterChart(datas) {
  642. var alChart = window["alScatterChart"];
  643. if (alChart == null || datas == null) return;
  644. //remove the old data in the chart
  645. alChart.data.labels.splice(0,alChart.data.labels.length);
  646. alChart.data.datasets.forEach((dataset) => {
  647. dataset.data.splice(0,dataset.data.length);
  648. });
  649. alChart.update();
  650. datas.forEach((data) => {
  651. alChart.data.datasets[0].data.push(warningValueMax);
  652. alChart.data.datasets[1].data.push(warningValueMin);
  653. alChart.data.datasets[2].data.push(data.VaporLiquidRatio);
  654. alChart.data.labels.push(data.FuellingEndTime);
  655. });
  656. if (alChart.data.labels.length < minimumScatterChartPoint) {
  657. var startDate = document.getElementById("StartDate").value+" 00:00:00";
  658. var endDate = document.getElementById("EndDate").value+" 23:59:59";
  659. alChart.data.datasets[0].data.unshift(warningValueMax);
  660. alChart.data.datasets[1].data.unshift(warningValueMin);
  661. alChart.data.datasets[2].data.unshift(0);
  662. alChart.data.labels.unshift(startDate);
  663. alChart.data.datasets[0].data.push(warningValueMax);
  664. alChart.data.datasets[1].data.push(warningValueMin);
  665. alChart.data.datasets[2].data.push(0);
  666. alChart.data.labels.push(endDate);
  667. }
  668. var i = 0;
  669. alChart.data.datasets[2].data.forEach((data) => {
  670. if (data > warningValueMax || data<warningValueMin) {
  671. config_scatterChart.data.datasets[2].borderColor[i] = '@warningPointColor';
  672. } else if (data === 0) {
  673. config_scatterChart.data.datasets[2].borderColor[i] = 'rgba(192, 192, 192, 0)';
  674. } else {
  675. config_scatterChart.data.datasets[2].borderColor[i] = '@normalPointColor';
  676. }
  677. i++;
  678. });
  679. alChart.update();
  680. }
  681. </script>