lineChartCarsimA.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. <template>
  2. <div class="linechart" :id="id" style="width: 100%; height: 100%"></div>
  3. </template>
  4. <script>
  5. import { mapState } from "vuex";
  6. export default {
  7. name: "lineChartCarsimA", // carsim-折线图
  8. props: {
  9. id: {
  10. default: "lineChartCarsimA",
  11. type: String,
  12. },
  13. dataList: {
  14. default: function () {
  15. return [];
  16. },
  17. type: Array,
  18. },
  19. dataListA: {
  20. default: function () {
  21. return [];
  22. },
  23. type: Array,
  24. },
  25. columns: {
  26. default: function () {
  27. return [];
  28. },
  29. type: Array,
  30. },
  31. },
  32. data() {
  33. return {
  34. tipData: [], //线数据
  35. showData: [], //展示数据
  36. charts: "",
  37. xName: "油门位置",
  38. yName: "低档输出转速(rpm)",
  39. };
  40. },
  41. watch: {
  42. dataList: {
  43. handler(val) {
  44. if (val.length > 0) {
  45. this.initStateList();
  46. }
  47. },
  48. deep: true,
  49. },
  50. dataListA: {
  51. handler(val) {
  52. if (val.length > 0) {
  53. this.initStateList();
  54. }
  55. },
  56. deep: true,
  57. },
  58. },
  59. computed: {
  60. ...mapState(["themeColor"]),
  61. },
  62. methods: {
  63. initStateList() {
  64. let array = this.dataList;
  65. let array1 = this.dataListA;
  66. for (let index = 0; index < array.length; index++) {
  67. const element = array[index];
  68. let flag = Object.values(element).some((i) => i === "");
  69. if (flag) {
  70. let option1 = {
  71. title: {
  72. text: "暂无数据",
  73. show: flag,
  74. left: "center",
  75. top: "center",
  76. },
  77. tooltip: {
  78. //提示框,可以在全局也可以在
  79. trigger: "item", //提示框的样式
  80. formatter: "{b}: {c}",
  81. color: "#000", //提示框的背景色
  82. textStyle: {
  83. //提示的字体样式
  84. color: "#ffffff",
  85. },
  86. confine: true,
  87. },
  88. xAxis: {
  89. name: this.xName,
  90. type: "category",
  91. boundaryGap: false,
  92. data: [],
  93. },
  94. yAxis: {
  95. name: this.yName,
  96. },
  97. series: [
  98. {
  99. data: [],
  100. type: "line",
  101. smooth: true,
  102. symbol: "circle",
  103. symbolSize: 6,
  104. lineStyle: {
  105. normal: {
  106. width: 1.5,
  107. // color: this.themeColor,
  108. },
  109. },
  110. itemStyle: {
  111. normal: {
  112. // color: this.themeColor,
  113. },
  114. },
  115. },
  116. ],
  117. grid: {
  118. top: "30px",
  119. left: "60px",
  120. right: "108px",
  121. bottom: "10%",
  122. containLabel: true,
  123. },
  124. };
  125. this.charts.clear();
  126. this.charts.setOption(option1);
  127. return;
  128. }
  129. }
  130. for (let index = 0; index < array1.length; index++) {
  131. const element = array1[index];
  132. let flag = Object.values(element).some((i) => i === "");
  133. if (flag) {
  134. let option1 = {
  135. title: {
  136. text: "暂无数据",
  137. show: flag,
  138. left: "center",
  139. top: "center",
  140. },
  141. tooltip: {
  142. //提示框,可以在全局也可以在
  143. trigger: "item", //提示框的样式
  144. formatter: "{b}: {c}",
  145. color: "#000", //提示框的背景色
  146. textStyle: {
  147. //提示的字体样式
  148. color: "#ffffff",
  149. },
  150. confine: true,
  151. },
  152. xAxis: {
  153. name: this.xName,
  154. type: "category",
  155. boundaryGap: false,
  156. data: [],
  157. },
  158. yAxis: {
  159. name: this.yName,
  160. },
  161. series: [
  162. {
  163. data: [],
  164. type: "line",
  165. smooth: true,
  166. symbol: "circle",
  167. symbolSize: 6,
  168. lineStyle: {
  169. normal: {
  170. width: 1.5,
  171. // color: this.themeColor,
  172. },
  173. },
  174. itemStyle: {
  175. normal: {
  176. // color: this.themeColor,
  177. },
  178. },
  179. },
  180. ],
  181. grid: {
  182. top: "30px",
  183. left: "60px",
  184. right: "108px",
  185. bottom: "10%",
  186. containLabel: true,
  187. },
  188. };
  189. this.charts.clear();
  190. this.charts.setOption(option1);
  191. return;
  192. }
  193. }
  194. let props = ["x", "y"];
  195. let xData = [];
  196. let yData = [];
  197. props.forEach((j) => {
  198. let arr = [];
  199. array.forEach((i) => {
  200. let a = i[j] || 0;
  201. if (j === "x") {
  202. xData.push(a);
  203. } else {
  204. arr.push(a);
  205. }
  206. });
  207. if (j != "x") yData.push(arr);
  208. });
  209. props.forEach((j) => {
  210. let arr = [];
  211. array1.forEach((i) => {
  212. let a = i[j] || 0;
  213. if (j != "x") {
  214. arr.push(a);
  215. }
  216. });
  217. if (j != "x") yData.push(arr);
  218. });
  219. let series = [];
  220. let names = ["up-shifting", "down-shifting"];
  221. yData.forEach((i, index) => {
  222. series.push({
  223. name: names[index],
  224. data: i,
  225. type: "line",
  226. smooth: true,
  227. symbol: "circle",
  228. symbolSize: 6,
  229. lineStyle: {
  230. normal: {
  231. width: 1.5,
  232. // color: this.themeColor,
  233. },
  234. },
  235. itemStyle: {
  236. normal: {
  237. // color: this.themeColor,
  238. },
  239. },
  240. });
  241. });
  242. let option = {
  243. title: {
  244. text: "暂无数据",
  245. show: yData.length === 0,
  246. left: "center",
  247. top: "center",
  248. },
  249. tooltip: {
  250. //提示框,可以在全局也可以在
  251. trigger: "item", //提示框的样式
  252. formatter: "{b}: {c}",
  253. color: "#000", //提示框的背景色
  254. textStyle: {
  255. //提示的字体样式
  256. color: "#ffffff",
  257. },
  258. confine: true,
  259. },
  260. xAxis: {
  261. name: this.xName,
  262. type: "category",
  263. boundaryGap: false,
  264. data: xData,
  265. // min: 0,
  266. // max: 1,
  267. },
  268. yAxis: {
  269. name: this.yName,
  270. },
  271. legend: {},
  272. series,
  273. grid: {
  274. top: "30px",
  275. left: "60px",
  276. right: "108px",
  277. bottom: "10%",
  278. containLabel: true,
  279. },
  280. };
  281. this.charts.setOption(option);
  282. },
  283. },
  284. mounted() {
  285. this.charts = this.$echarts.init(document.getElementById(this.id));
  286. this.initStateList();
  287. this.$nextTick(() => {
  288. window.addEventListener("resize", () => {
  289. this.charts.resize();
  290. });
  291. });
  292. },
  293. destroyed() {
  294. this.charts.dispose();
  295. },
  296. };
  297. </script>
  298. <style lang='less' scoped>
  299. .linechart {
  300. margin: 0 auto;
  301. overflow: hidden;
  302. }
  303. </style>