echartsHFCD.vue 9.0 KB

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