cylindricalHistogram.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. <!-- 圆柱柱状图 -->
  2. <template>
  3. <div>
  4. <boxTop :title="title" />
  5. <div class="oblongBox">
  6. <div class="chartsdom" id="cylindrical"></div>
  7. </div>
  8. </div>
  9. </template>
  10. <script>
  11. import boxTop from '@/components/boxTop/index.vue'
  12. export default {
  13. data() {
  14. return {
  15. option: null,
  16. information: {},
  17. }
  18. },
  19. components: {
  20. boxTop,
  21. },
  22. props: {
  23. barWidth: {
  24. type: Number,
  25. },
  26. area: {
  27. type: Array,
  28. },
  29. dataArray: {
  30. type: Array,
  31. },
  32. title: {
  33. type: String,
  34. default: ``,
  35. },
  36. unit: {
  37. type: String,
  38. },
  39. },
  40. mounted() {
  41. this.getEchart()
  42. },
  43. watch: {
  44. dataArray() {
  45. this.getEchart()
  46. },
  47. },
  48. methods: {
  49. getEchart() {
  50. let myChart = echarts.init(document.getElementById(`cylindrical`))
  51. this.information = {
  52. barWidth: 10,
  53. colorArray: {
  54. lineColor: `rgba(199,214,242, 0.2)`,
  55. labelColor: ` #c7d6f2`,
  56. },
  57. unit: this.unit,
  58. area: this.area,
  59. dataArray: this.dataArray,
  60. }
  61. this.option = {
  62. // animation: false, //去除加载时缓动动画
  63. tooltip: {
  64. trigger: `axis`,
  65. backgroundColor: `rgba(0, 0, 0, 0.8)`,
  66. textStyle: {
  67. color: `#fff`,
  68. },
  69. axisPointer: {
  70. lineStyle: {
  71. color: `transparent`,
  72. },
  73. },
  74. formatter: function (params) {
  75. console.log(params, `111111`)
  76. return [params[0].value].join(`<br>`)
  77. },
  78. },
  79. xAxis: {
  80. axisLine: {
  81. lineStyle: {
  82. color: this.information.colorArray.lineColor,
  83. },
  84. },
  85. axisTick: {
  86. show: false,
  87. },
  88. axisLabel: {
  89. color: this.information.colorArray.labelColor,
  90. fontSize: 12,
  91. margin: 15,
  92. interval: 0,
  93. },
  94. splitLine: {
  95. show: true,
  96. interval: this.information.area.length,
  97. lineStyle: {
  98. color: this.information.colorArray.lineColor,
  99. width: 1,
  100. },
  101. },
  102. data: this.information.area,
  103. },
  104. grid: {
  105. left: `6%`,
  106. right: `6%`,
  107. bottom: `8%`,
  108. top: `24%`,
  109. containLabel: true,
  110. },
  111. yAxis: [
  112. {
  113. type: `value`,
  114. name: this.information.unit,
  115. nameTextStyle: {
  116. color: `#65ABE7`,
  117. fontSize: 12,
  118. },
  119. axisTick: {
  120. show: false,
  121. },
  122. splitLine: {
  123. show: true,
  124. lineStyle: {
  125. color: this.information.colorArray.lineColor,
  126. width: 2,
  127. },
  128. },
  129. axisLabel: {
  130. margin: 20,
  131. color: this.information.colorArray.labelColor,
  132. fontSize: 12,
  133. fontWeight: 4,
  134. },
  135. axisLine: {
  136. show: true,
  137. lineStyle: {
  138. color: this.information.colorArray.lineColor,
  139. width: 2,
  140. },
  141. },
  142. },
  143. ],
  144. series: [
  145. {
  146. name: this.information.unit,
  147. tooltip: {
  148. show: true,
  149. },
  150. type: `bar`,
  151. barWidth: this.information.barWidth, // 柱子宽度
  152. label: {
  153. show: false,
  154. position: `top`,
  155. padding: 10,
  156. fontSize: 20,
  157. color: `#00ffff`,
  158. fontWeight: `bold`,
  159. },
  160. itemStyle: {
  161. color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
  162. {
  163. offset: 0,
  164. color: `#47FEED`,
  165. },
  166. {
  167. offset: 1,
  168. color: `#0E7E7D`,
  169. },
  170. ]),
  171. },
  172. data: this.information.dataArray,
  173. legendHoverLink: false,
  174. },
  175. {
  176. // 柱子底部椭圆
  177. name: `报修数量`,
  178. tooltip: {
  179. show: false,
  180. },
  181. type: `pictorialBar`,
  182. itemStyle: {
  183. // 未填充部分鼠标移上去颜色
  184. color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
  185. {
  186. offset: 0,
  187. color: `#1ABFC0`,
  188. },
  189. {
  190. offset: 1,
  191. color: `#1ABFC0`,
  192. },
  193. ]),
  194. },
  195. symbolRotate: 0,
  196. symbolSize: [this.information.barWidth, 5],
  197. symbolOffset: [0, 3],
  198. symbolPosition: `start`,
  199. data: this.information.dataArray,
  200. z: 3,
  201. },
  202. {
  203. // 柱子头部椭圆
  204. name: `报修数量`,
  205. tooltip: {
  206. show: false,
  207. },
  208. type: `pictorialBar`,
  209. itemStyle: {
  210. color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
  211. {
  212. offset: 0,
  213. color: `#1ABFC0`,
  214. },
  215. {
  216. offset: 1,
  217. color: `#1ABFC0`,
  218. },
  219. ]),
  220. },
  221. symbolRotate: 0,
  222. symbolSize: [this.information.barWidth, 5],
  223. symbolOffset: [0, -3],
  224. symbolPosition: `end`,
  225. data: this.information.dataArray,
  226. z: 3,
  227. },
  228. ],
  229. }
  230. myChart.setOption(this.option, true)
  231. },
  232. },
  233. beforeDestroy() {},
  234. }
  235. </script>
  236. <style lang="less" scoped>
  237. .oblongBox {
  238. width: 401px;
  239. height: 275px;
  240. .chartsdom {
  241. width: 100%;
  242. height: 100%;
  243. }
  244. }
  245. </style>