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

LineChart.vue 6.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  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(a) {
  78. // console.log(a)
  79. // this.chartOptions = this.options;
  80. // this.initChart();
  81. // this.__resizeHanlder = debounce(() => {
  82. // if (this.chart) {
  83. // this.chart.resize();
  84. // }
  85. // }, 100);
  86. // window.addEventListener("resize", this.__resizeHanlder);
  87. // },
  88. options:{
  89. handler(newValue,oldValue){
  90. this.getInitChart();
  91. },
  92. deep:true
  93. },
  94. chartData: {
  95. deep: true,
  96. handler(val) {
  97. this.setOptions(val);
  98. }
  99. }
  100. },
  101. created() {
  102. this.chartOptions = this.options;
  103. // console.log("this.chartOptions", this.chartOptions, this.options);
  104. },
  105. methods: {
  106. getInitChart() {
  107. this.chartOptions = this.options;
  108. this.initChart();
  109. this.__resizeHanlder = debounce(() => {
  110. if (this.chart) {
  111. this.chart.resize();
  112. }
  113. }, 100);
  114. window.addEventListener("resize", this.__resizeHanlder);
  115. },
  116. // setOptions({ expectedData, actualData } = {}) {
  117. // this.chart.setOption({
  118. // title: {
  119. // text: this.title,
  120. // },
  121. // xAxis: {
  122. // data: this.chartOptions.xAxis,
  123. // boundaryGap: false,
  124. // axisTick: {
  125. // show: false
  126. // }
  127. // },
  128. // grid: {
  129. // left: 50,
  130. // right: 50,
  131. // bottom: 20,
  132. // top: 30,
  133. // containLabel: true
  134. // },
  135. // tooltip: {
  136. // trigger: 'axis',
  137. // axisPointer: {
  138. // type: 'cross'
  139. // },
  140. // padding: [5, 10]
  141. // },
  142. // yAxis: {
  143. // axisTick: {
  144. // show: false
  145. // }
  146. // },
  147. // legend: {
  148. // data: this.chartOptions.legend,
  149. // },
  150. // series: this.chartOptions.series,
  151. // })
  152. // },
  153. setOptions({ expectedData, actualData } = {}) {
  154. this.chart.setOption({
  155. // title: {
  156. // text: this.title
  157. // },
  158. xAxis: {
  159. data: this.chartOptions.xAxis.data,
  160. // boundaryGap: false
  161. axisTick: {
  162. show: true
  163. },
  164. axisLine: {
  165. lineStyle: {
  166. color: "#E5E5E5" //x轴颜色
  167. }
  168. },
  169. axisLabel: {
  170. interval: 0,
  171. formatter: function(value) {
  172. var ret = ""; //拼接加\n返回的类目项
  173. var maxLength = 10; //每项显示文字个数
  174. var valLength = value.length; //X轴类目项的文字个数
  175. var rowN = Math.ceil(valLength / maxLength); //类目项需要换行的行数
  176. if (rowN > 1) {
  177. //如果类目项的文字大于3,
  178. for (var i = 0; i < rowN; i++) {
  179. var temp = ""; //每次截取的字符串
  180. var start = i * maxLength; //开始截取的位置
  181. var end = start + maxLength; //结束截取的位置
  182. //这里也可以加一个是否是最后一行的判断,但是不加也没有影响,那就不加吧
  183. temp = value.substring(start, end) + "\n";
  184. ret += temp; //凭借最终的字符串
  185. }
  186. return ret;
  187. } else {
  188. return value;
  189. }
  190. },
  191. textStyle: {
  192. color:"#2F3133"
  193. }
  194. }
  195. },
  196. grid: {
  197. left: 0,
  198. right: 50,
  199. bottom: 10,
  200. top: 30,
  201. containLabel: true
  202. },
  203. tooltip: {
  204. trigger: "axis",
  205. axisPointer: {
  206. type: "cross"
  207. },
  208. padding: [5, 10]
  209. },
  210. yAxis: {
  211. axisTick: {
  212. show: true
  213. },
  214. axisLine: {
  215. lineStyle: {
  216. color: "#E5E5E5" //y轴颜色
  217. },
  218. },
  219. axisLabel: {
  220. textStyle: {
  221. color:"#2F3133"
  222. }
  223. }
  224. },
  225. // dataZoom: [
  226. // {
  227. // //Y轴固定,让内容滚动
  228. // type: "slider",
  229. // show: false,
  230. // xAxisIndex: [0],
  231. // start: 1,
  232. // end: 80, //设置X轴刻度之间的间隔(根据数据量来调整)
  233. // zoomLock: true //锁定区域禁止缩放(鼠标滚动会缩放,所以禁止)
  234. // },
  235. // {
  236. // type: "inside",
  237. // xAxisIndex: [0],
  238. // start: 1,
  239. // end: 80,
  240. // zoomLock: true //锁定区域禁止缩放
  241. // }
  242. // ],
  243. legend: this.chartOptions.legend,
  244. series: this.chartOptions.series,
  245. dataZoom: this.chartOptions.dataZoom,
  246. });
  247. },
  248. initChart() {
  249. this.chart = echarts.init(this.$el, "macarons");
  250. this.chart.clear();
  251. this.setOptions(this.chartData);
  252. }
  253. }
  254. };
  255. </script>