HeightDistribution.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. <template>
  2. <div>
  3. <div>
  4. <div ref="chart" class="item" style="height: 300px" />
  5. </div>
  6. </div>
  7. </template>
  8. <script>
  9. import * as echarts from "echarts";
  10. import toolUtils from "@/utils/echartsTooltip";
  11. export default {
  12. data() {
  13. return {
  14. chart: null,
  15. timer: "",
  16. dataList: [],
  17. };
  18. },
  19. props: {
  20. list: {
  21. type: Array,
  22. default: [],
  23. },
  24. },
  25. watch: {
  26. list: {
  27. handler(val) {
  28. this.$nextTick(() => {
  29. const chartDom = this.$refs.chart;
  30. // 初始化图表实例
  31. this.chart = echarts.init(chartDom);
  32. this.initChart(val);
  33. });
  34. },
  35. immediate: true,
  36. deep: true,
  37. },
  38. },
  39. methods: {
  40. initChart(data) {
  41. const x = [];
  42. data.forEach((p) => {
  43. if (x.indexOf(p.gd) < 0) {
  44. x.push(p.gd);
  45. }
  46. });
  47. const sideData = [];
  48. x.forEach((p) => {
  49. const val = data.find((k) => k.gd === p);
  50. sideData.push(val.sl);
  51. });
  52. // const datalsit = [220, 182, 191, 234, 290, 330, 310];
  53. // const sideData = datalsit.map((item) => item + 4.5);
  54. const option = {
  55. // backgroundColor: "#041730",
  56. tooltip: {
  57. trigger: "axis",
  58. formatter: "{b} : {c}",
  59. axisPointer: {
  60. // 坐标轴指示器,坐标轴触发有效
  61. type: "shadow", // 默认为直线,可选为:'line' | 'shadow'
  62. },
  63. extraCssText: "z-index: 1000;"
  64. },
  65. title: {
  66. top: "5%",
  67. right: "2%",
  68. text: "单位:栋",
  69. textStyle: {
  70. align: "center",
  71. color: "#fff",
  72. fontSize: 12,
  73. },
  74. },
  75. grid: {
  76. right: "10px",
  77. },
  78. xAxis: {
  79. data: [
  80. "30m及以下",
  81. "30~50m(含)",
  82. "50~80m(含)",
  83. "80~100m(含)",
  84. "100m以上",
  85. ],
  86. //坐标轴
  87. axisLine: {
  88. lineStyle: {
  89. color: "#3eb2e8",
  90. },
  91. },
  92. axisTick: {
  93. //y轴刻度线
  94. show: false,
  95. },
  96. //坐标值标注
  97. axisLabel: {
  98. show: true,
  99. textStyle: {
  100. color: "#fff",
  101. fontSize: 9,
  102. },
  103. },
  104. },
  105. yAxis: {
  106. //坐标轴
  107. axisLine: {
  108. show: false,
  109. },
  110. axisTick: {
  111. //y轴刻度线
  112. show: false,
  113. },
  114. //坐标值标注
  115. axisLabel: {
  116. show: true,
  117. textStyle: {
  118. color: "#fff",
  119. },
  120. },
  121. //分格线
  122. splitLine: {
  123. lineStyle: {
  124. color: "#4784e8",
  125. type: "dashed",
  126. },
  127. },
  128. },
  129. series: [
  130. {
  131. type: "bar",
  132. barWidth: 20,
  133. label: {
  134. show: true,
  135. color: "#fff",
  136. position: "top",
  137. },
  138. itemStyle: {
  139. normal: {
  140. color: new echarts.graphic.LinearGradient(
  141. 0,
  142. 1,
  143. 0,
  144. 0,
  145. [
  146. {
  147. offset: 0,
  148. color: "rgba(0,209,255, 1)", // 0% 处的颜色
  149. },
  150. {
  151. offset: 1,
  152. color: "rgba(0, 255,224, .87)", // 100% 处的颜色
  153. },
  154. ],
  155. false
  156. ),
  157. },
  158. },
  159. barGap: 0,
  160. data: sideData,
  161. },
  162. ],
  163. };
  164. this.chart.setOption(option);
  165. //自适应图表
  166. window.onresize = this.chart.resize;
  167. // 自动轮播
  168. console.log(data);
  169. toolUtils.autoHover(this.chart, option, data.length, 5000);
  170. },
  171. openBasicModal() {
  172. this.showModal("basicInfoModal");
  173. },
  174. },
  175. // mounted() {
  176. // const chartDom = this.$refs.chart;
  177. // // // 初始化图表实例
  178. // this.chart = echarts.init(chartDom);
  179. // this.initChart(this.dataList);
  180. // },
  181. };
  182. </script>
  183. <style scoped></style>