Elizabeth's proactive approach involves introducing urinal toilet attachment , an ingenious concept that optimizes space and functionality.

LineChart.vue 6.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. <template>
  2. <div :class="className" :style="{height:height,width:width}"></div>
  3. </template>
  4. <script>
  5. import echarts from "echarts";
  6. require("echarts/theme/macarons"); // echarts theme
  7. import { debounce } from "@/utils";
  8. export default {
  9. props: {
  10. className: {
  11. type: String,
  12. default: "chart"
  13. },
  14. width: {
  15. type: String,
  16. default: "100%"
  17. },
  18. height: {
  19. type: String,
  20. default: "230px"
  21. },
  22. autoResize: {
  23. type: Boolean,
  24. default: true
  25. },
  26. chartData: {
  27. type: Object
  28. },
  29. title: {
  30. type: String,
  31. default: "chart"
  32. },
  33. options: {
  34. type: Object,
  35. default: function() {
  36. return {};
  37. }
  38. }
  39. },
  40. data() {
  41. return {
  42. chart: null,
  43. chartOptions: {
  44. xAxis: [],
  45. legend: [],
  46. series: []
  47. }
  48. };
  49. },
  50. mounted() {
  51. this.initChart();
  52. if (this.autoResize) {
  53. this.__resizeHanlder = debounce(() => {
  54. if (this.chart) {
  55. this.chart.resize();
  56. }
  57. }, 100);
  58. window.addEventListener("resize", this.__resizeHanlder);
  59. }
  60. // 监听侧边栏的变化
  61. const sidebarElm = document.getElementsByClassName("sidebar-container")[0];
  62. sidebarElm.addEventListener("transitionend", this.__resizeHanlder);
  63. },
  64. beforeDestroy() {
  65. if (!this.chart) {
  66. return;
  67. }
  68. if (this.autoResize) {
  69. window.removeEventListener("resize", this.__resizeHanlder);
  70. }
  71. const sidebarElm = document.getElementsByClassName("sidebar-container")[0];
  72. sidebarElm.removeEventListener("transitionend", this.__resizeHanlder);
  73. this.chart.dispose();
  74. this.chart = null;
  75. },
  76. watch: {
  77. options: function() {
  78. this.chartOptions = this.options;
  79. this.initChart();
  80. this.__resizeHanlder = debounce(() => {
  81. if (this.chart) {
  82. this.chart.resize();
  83. }
  84. }, 100);
  85. window.addEventListener("resize", this.__resizeHanlder);
  86. },
  87. chartData: {
  88. deep: true,
  89. handler(val) {
  90. this.setOptions(val);
  91. }
  92. }
  93. },
  94. created() {
  95. this.chartOptions = this.options;
  96. console.log("this.chartOptions", this.chartOptions, this.options);
  97. },
  98. methods: {
  99. // setOptions({ expectedData, actualData } = {}) {
  100. // this.chart.setOption({
  101. // title: {
  102. // text: this.title,
  103. // },
  104. // xAxis: {
  105. // data: this.chartOptions.xAxis,
  106. // boundaryGap: false,
  107. // axisTick: {
  108. // show: false
  109. // }
  110. // },
  111. // grid: {
  112. // left: 50,
  113. // right: 50,
  114. // bottom: 20,
  115. // top: 30,
  116. // containLabel: true
  117. // },
  118. // tooltip: {
  119. // trigger: 'axis',
  120. // axisPointer: {
  121. // type: 'cross'
  122. // },
  123. // padding: [5, 10]
  124. // },
  125. // yAxis: {
  126. // axisTick: {
  127. // show: false
  128. // }
  129. // },
  130. // legend: {
  131. // data: this.chartOptions.legend,
  132. // },
  133. // series: this.chartOptions.series,
  134. // })
  135. // },
  136. setOptions({ expectedData, actualData } = {}) {
  137. this.chart.setOption({
  138. // title: {
  139. // text: this.title
  140. // },
  141. xAxis: {
  142. data: this.chartOptions.xAxis.data,
  143. // boundaryGap: false
  144. axisTick: {
  145. show: true
  146. },
  147. axisLine: {
  148. lineStyle: {
  149. color: "#E5E5E5" //x轴颜色
  150. }
  151. },
  152. axisLabel: {
  153. interval: 0,
  154. formatter: function(value) {
  155. var ret = ""; //拼接加\n返回的类目项
  156. var maxLength = 8; //每项显示文字个数
  157. var valLength = value.length; //X轴类目项的文字个数
  158. var rowN = Math.ceil(valLength / maxLength); //类目项需要换行的行数
  159. if (rowN > 1) {
  160. //如果类目项的文字大于3,
  161. for (var i = 0; i < rowN; i++) {
  162. var temp = ""; //每次截取的字符串
  163. var start = i * maxLength; //开始截取的位置
  164. var end = start + maxLength; //结束截取的位置
  165. //这里也可以加一个是否是最后一行的判断,但是不加也没有影响,那就不加吧
  166. temp = value.substring(start, end) + "\n";
  167. ret += temp; //凭借最终的字符串
  168. }
  169. return ret;
  170. } else {
  171. return value;
  172. }
  173. },
  174. textStyle: {
  175. color:"#2F3133"
  176. }
  177. }
  178. },
  179. grid: {
  180. left: 0,
  181. right: 50,
  182. bottom: 10,
  183. top: 30,
  184. containLabel: true
  185. },
  186. tooltip: {
  187. trigger: "axis",
  188. axisPointer: {
  189. type: "cross"
  190. },
  191. padding: [5, 10]
  192. },
  193. yAxis: {
  194. axisTick: {
  195. show: true
  196. },
  197. axisLine: {
  198. lineStyle: {
  199. color: "#E5E5E5" //y轴颜色
  200. },
  201. },
  202. axisLabel: {
  203. textStyle: {
  204. color:"#2F3133"
  205. }
  206. }
  207. },
  208. // dataZoom: [
  209. // {
  210. // //Y轴固定,让内容滚动
  211. // type: "slider",
  212. // show: false,
  213. // xAxisIndex: [0],
  214. // start: 1,
  215. // end: 80, //设置X轴刻度之间的间隔(根据数据量来调整)
  216. // zoomLock: true //锁定区域禁止缩放(鼠标滚动会缩放,所以禁止)
  217. // },
  218. // {
  219. // type: "inside",
  220. // xAxisIndex: [0],
  221. // start: 1,
  222. // end: 80,
  223. // zoomLock: true //锁定区域禁止缩放
  224. // }
  225. // ],
  226. legend: this.chartOptions.legend,
  227. series: this.chartOptions.series
  228. });
  229. },
  230. initChart() {
  231. this.chart = echarts.init(this.$el, "macarons");
  232. this.chart.clear();
  233. this.setOptions(this.chartData);
  234. }
  235. }
  236. };
  237. </script>