arrow-dash-line-chart.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. <template>
  2. <div class="chart" :id="id"></div>
  3. </template>
  4. <script>
  5. import util from "@/helper/util.js";
  6. import partten from "@/helper/partten.js";
  7. import * as echarts from "echarts";
  8. export default {
  9. name: "multi-arrow-line-chart",
  10. componentName: "multi-arrow-line-chart",
  11. props: {
  12. width: {
  13. type: String,
  14. default: "100%",
  15. },
  16. height: {
  17. type: String,
  18. default: "13.889vh",
  19. },
  20. // 数据
  21. list: {
  22. type: Array,
  23. default: () => [
  24. {
  25. title: "功率",
  26. yAxisIndex: 0,
  27. value: [
  28. {
  29. text: "0m/s",
  30. value: 1,
  31. },
  32. {
  33. text: "2m/s",
  34. value: 2,
  35. },
  36. {
  37. text: "3m/s",
  38. value: 16,
  39. },
  40. {
  41. text: "4m/s",
  42. value: 3,
  43. },
  44. {
  45. text: "5m/s",
  46. value: 3,
  47. },
  48. {
  49. text: "6m/s",
  50. value: 31,
  51. },
  52. {
  53. text: "7m/s",
  54. value: 33,
  55. },
  56. {
  57. text: "8m/s",
  58. value: 43,
  59. },
  60. {
  61. text: "9m/s",
  62. value: 3,
  63. },
  64. {
  65. text: "10m/s",
  66. value: 3,
  67. },
  68. {
  69. text: "11m/s",
  70. value: 31,
  71. },
  72. {
  73. text: "12m/s",
  74. value: 3,
  75. },
  76. {
  77. text: "13m/s",
  78. value: 3,
  79. },
  80. ],
  81. },
  82. ],
  83. },
  84. // 单位
  85. units: {
  86. type: Array,
  87. default: () => ["()"],
  88. },
  89. showLegend: {
  90. type: Boolean,
  91. default: true,
  92. },
  93. },
  94. data() {
  95. return {
  96. id: "",
  97. chart: null,
  98. color: ["#606769"],
  99. };
  100. },
  101. computed: {
  102. legend() {
  103. return this.list.map((t) => {
  104. return t.title;
  105. });
  106. },
  107. xdata() {
  108. return this.list[0].value.map((t) => {
  109. return t.text;
  110. });
  111. },
  112. yAxis() {
  113. let result = [];
  114. this.units.forEach((value, index) => {
  115. result.push({
  116. type: "value",
  117. name: value,
  118. axisLabel: {
  119. formatter: "{value}",
  120. fontSize: util.vh(14),
  121. },
  122. //分格线
  123. splitLine: {
  124. lineStyle: {
  125. color: partten.getColor("gray") + 55,
  126. type: "dashed",
  127. },
  128. },
  129. });
  130. });
  131. return result;
  132. },
  133. series() {
  134. let result = [];
  135. this.list.forEach((value, index) => {
  136. var data = value.value.map((t) => {
  137. return t.value;
  138. });
  139. var arrowArr = [];
  140. data.forEach((dvalue, dindex) => {
  141. var item = dvalue;
  142. if (dindex < data.length / 2) {
  143. arrowArr.push({
  144. symbol: "arrow",
  145. symbolSize: 12,
  146. symbolRotate: -90,
  147. value: item,
  148. });
  149. } else {
  150. arrowArr.push({ symbol: "none", value: item });
  151. }
  152. });
  153. result.push({
  154. name: value.title,
  155. type: "line",
  156. smooth: true,
  157. zlevel: index,
  158. lineStyle: {
  159. type: "dotted", //dashed
  160. },
  161. yAxisIndex: value.yAxisIndex,
  162. data: arrowArr,
  163. });
  164. });
  165. return result;
  166. },
  167. },
  168. methods: {
  169. initChart() {
  170. const chart = echarts.init(this.$el);
  171. let option = {
  172. color: this.color,
  173. tooltip: {
  174. trigger: "axis",
  175. backgroundColor: "rgba(0,0,0,0.4)",
  176. borderColor: partten.getColor("gray"),
  177. textStyle: {
  178. color: "#fff",
  179. fontSize: util.vh(16),
  180. },
  181. },
  182. legend: {
  183. show: this.showLegend,
  184. data: this.legend,
  185. right: 56,
  186. icon: "circle",
  187. itemWidth: 6,
  188. inactiveColor: partten.getColor("gray"),
  189. textStyle: {
  190. color: partten.getColor("grayl"),
  191. fontSize: 12,
  192. },
  193. },
  194. grid: {
  195. top: util.vh(32),
  196. left: util.vh(40),
  197. right: util.vh(40),
  198. bottom: util.vh(24),
  199. },
  200. xAxis: [
  201. {
  202. type: "category",
  203. boundaryGap: false,
  204. axisLabel: {
  205. formatter: "{value}",
  206. fontSize: util.vh(14),
  207. textStyle: {
  208. color: partten.getColor("gray"),
  209. },
  210. },
  211. data: this.xdata,
  212. },
  213. ],
  214. yAxis: this.yAxis,
  215. series: this.series,
  216. };
  217. chart.clear();
  218. chart.setOption(option);
  219. this.resize = function() {
  220. chart.resize();
  221. };
  222. window.addEventListener("resize", this.resize);
  223. },
  224. },
  225. created() {
  226. this.id = "pie-chart-" + util.newGUID();
  227. },
  228. mounted() {
  229. this.$nextTick(() => {
  230. this.$el.style.width = this.width;
  231. this.$el.style.height = this.height;
  232. this.initChart();
  233. });
  234. },
  235. updated() {
  236. this.$nextTick(() => {
  237. this.initChart();
  238. });
  239. },
  240. unmounted() {
  241. window.removeEventListener("resize", this.resize);
  242. },
  243. };
  244. </script>
  245. <style lang="less">
  246. .chart {
  247. width: 100%;
  248. height: 100%;
  249. display: inline-block;
  250. }
  251. </style>