echartsHFCD.vue 9.0 KB

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