echartsHFCD.vue 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. <template>
  2. <div>
  3. <div class="x-bar" v-show="container_show">
  4. <div id="container"></div>
  5. </div>
  6. </div>
  7. </template>
  8. <script>
  9. import Highcharts from "highcharts"; //必须引入
  10. import { kgReplace, ugread } from "./Util.js";
  11. import { options } from 'runjs';
  12. import { request } from "@/utils/request";
  13. export default {
  14. data() {
  15. return {
  16. container_show:false,
  17. chart: null,
  18. convergeDate: { title: "hcfd", VARIABLES: [], value: [] },
  19. numlist:[],
  20. s1:'',
  21. };
  22. },
  23. components:{
  24. },
  25. props:{
  26. name:String,
  27. projectId:String,
  28. lsolverState:String,
  29. numzhexian:String,
  30. nmlsteps:Number,
  31. },
  32. mounted: function () {
  33. // this.oldlog()
  34. Highcharts.setOptions({
  35. global: {
  36. useUTC: false,
  37. },
  38. });
  39. let _this = this;
  40. // this.getwebsocket();
  41. },
  42. methods: {
  43. hiden(){
  44. this.container_show=false;
  45. },
  46. nhiden(){
  47. this.container_show=true;
  48. },
  49. // 时间换算
  50. timedata(d1, d2,s1){
  51. var date1 = new Date(d1); //开始时间
  52. var date2 = new Date(d2); //结束时间
  53. var cydata=(date2.getTime() - new Date(date1).getTime())/s1*(Number(this.nmlsteps)-s1);
  54. // var Milliseconds = date2.getTime() - new Date(date1).getTime(); //时间差的毫秒数
  55. var Milliseconds = cydata;
  56. //计算出相差天数
  57. var days = Math.floor(Milliseconds / (24 * 3600 * 1000))
  58. //计算出小时数
  59. var leave1 = Milliseconds % (24 * 3600 * 1000) //计算天数后剩余的毫秒数
  60. var hours = Math.floor(leave1 / (3600 * 1000))
  61. //计算相差分钟数
  62. var leave2 = leave1 % (3600 * 1000) //计算小时数后剩余的毫秒数
  63. var minutes = Math.floor(leave2 / (60 * 1000))
  64. //计算相差秒数
  65. var leave3 = leave2 % (60 * 1000) //计算分钟数后剩余的毫秒数
  66. var seconds = Math.round(leave3 / 1000)
  67. var ResultJson = {
  68. days: {
  69. days: days >= 0 ? days : days + 1,
  70. hours: hours >= 0 ? hours: hours + 1,
  71. minutes: minutes >= 0 ? minutes : minutes + 1,
  72. seconds: seconds >= 0 ? seconds: seconds + 1
  73. },
  74. Milliseconds: Milliseconds
  75. };
  76. //console.log(ResultJson)
  77. let year=ResultJson.days.days+'天'+ this.p(ResultJson.days.hours)+':'+ this.p(ResultJson.days.minutes)+':'+ this.p(ResultJson.days.seconds)
  78. this.$emit('restimeyear',year);
  79. return year;
  80. },
  81. p(s) {
  82. return s < 10 ? '0' + s: s;
  83. },
  84. // 获取求解日志
  85. newlog(){
  86. let params = {
  87. transCode: "C00006",
  88. pid: this.projectId,
  89. lesseeId: this.$store.getters.lesseeId
  90. };
  91. request(params)
  92. .then((res) => {
  93. console.log(res);
  94. })
  95. },
  96. //获取历史数据每一条
  97. historydata(){
  98. let params = {
  99. transCode: "C00007",
  100. pid: this.projectId,
  101. lesseeId: this.$store.getters.lesseeId
  102. };
  103. request(params)
  104. .then((res) => {
  105. console.log(res)
  106. })
  107. },
  108. // websocket
  109. getwebsocket() {
  110. // 初始化weosocket
  111. this.numlist=[];
  112. const wsuri = "ws://192.168.0.43:8031/websocket?projectId="+this.projectId;
  113. this.websock = new WebSocket(wsuri);
  114. this.websock.onmessage = this.websocketonmessage;
  115. this.websock.onopen = this.websocketonopen;
  116. this.websock.onerror = this.websocketonerror;
  117. this.websock.onclose = this.websocketclose;
  118. },
  119. websocketonopen(e) {
  120. //连接建立之后执行send方法发送数据this.newlog();
  121. // if(this.lsolverState=='1'||this.numzhexian=='1'){
  122. this.newlog();
  123. //this.historydata()
  124. // }
  125. },
  126. websocketonerror() {
  127. //连接建立失败重连
  128. this.websock.close();
  129. },
  130. websocketonmessage(e) {
  131. //数据接收
  132. try{
  133. const redata = JSON.parse(e.data);
  134. console.log(redata);
  135. if(typeof redata==='object'&& redata){
  136. if(redata.type == "log"){
  137. this.$emit('getthislog',redata.stats+redata.value);
  138. }
  139. if (redata.type == "iter") {
  140. this.convergeDateLoad(redata.value);
  141. //获取运行多少步了
  142. const lines = redata.value;
  143. var patiter = /^ iter /;
  144. if (patiter.exec(lines) !== null) {
  145. const onelines = kgReplace(lines.trim()).split(" ")
  146. .map((str) => str.trim());
  147. this.s1= onelines.slice(1,2).map((str) => Number(str));
  148. }
  149. this.timedata(redata.startTime,redata.time,this.s1[0]);
  150. }
  151. }
  152. }catch(error){
  153. return false;
  154. }
  155. },
  156. websocketsend(Data) {
  157. //数据发送
  158. this.websock.send(Data);
  159. },
  160. websocketclose(e) {
  161. //关闭
  162. Message({
  163. type: "error",
  164. message: "websock断开连接",
  165. });
  166. this.websock.close();
  167. },
  168. convergeDateLoad(data) {
  169. const lines = data;
  170. if(this.numlist.includes(lines)){
  171. }else{
  172. this.numlist.push(lines);
  173. var patIter = /^ Iter /;
  174. var patiter = /^ iter /;
  175. if (patIter.exec(lines) !== null) {
  176. const onelines = kgReplace(lines.trim())
  177. .split(" ")
  178. .map((str) => str.trim());
  179. let VARIABLES = onelines.slice(1);
  180. this.convergeDate.VARIABLES=VARIABLES;
  181. this.HighchartsData();
  182. }
  183. if (patiter.exec(lines) !== null) {
  184. const onelines = kgReplace(lines.trim()).split(" ")
  185. .map((str) => str.trim());
  186. let data = onelines.slice(2).map((str) => Number(str));
  187. let num= onelines.slice(1,2).map((str) => Number(str));
  188. this.convergeDate.value.push(
  189. onelines.slice(2).map((str) => Number(str))
  190. );
  191. for (var i in this.convergeDate.VARIABLES) {
  192. var series = this.chart.series[i];
  193. series.addPoint([Number(onelines[1]),data[i]]);
  194. }
  195. }
  196. }
  197. },
  198. activeLastPointToolip(chart) {
  199. var points = chart.series[0].points;
  200. chart.tooltip.refresh(points[points.length - 1]);
  201. },
  202. HighchartsData() {
  203. let _this = this;
  204. let option={
  205. title: {
  206. text: "HCFD",
  207. },
  208. credits:{
  209. enabled:false,
  210. },
  211. chart: {
  212. plotBackgroundColor: "rgba(0,0,0,0)",
  213. // borderWidth: 1,
  214. backgroundColor: "rgba(0,0,0,0)",
  215. },
  216. yAxis: {},
  217. xAxis: {},
  218. plotOptions: {
  219. series: {
  220. lineWidth: 2,
  221. label: {
  222. connectorAllowed: false,
  223. },
  224. marker: {
  225. radius: 5,
  226. },
  227. pointStart: 1,
  228. },
  229. },
  230. tooltip: {},
  231. legend: {
  232. layout: "horizontal",
  233. align: "center",
  234. verticalAlign: "bottom",
  235. },
  236. series: [
  237. // {
  238. // name: "随机数据",
  239. // data: (function () {
  240. // // 生成随机值
  241. // var data = [],
  242. // time = new Date().getTime(),
  243. // i;
  244. // for (i = -19; i <= 0; i += 1) {
  245. // data.push({
  246. // x: time + i * 1000,
  247. // y: Math.random(),
  248. // });
  249. // }
  250. // return data;
  251. // })(),
  252. // },
  253. ],
  254. }
  255. for (var i in _this.convergeDate.VARIABLES) {
  256. var obj = {
  257. name: "",
  258. data: [0, 0],
  259. color: "",
  260. display: true,
  261. };
  262. obj.name = _this.convergeDate.VARIABLES[i];
  263. option.series.push(obj);
  264. }
  265. option.title.text=this.name;
  266. _this.chart = Highcharts.chart("container", option);
  267. // console.log(_this.chart.series)
  268. },
  269. },
  270. };
  271. </script>