lineChartCarsimA.vue 9.6 KB

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