cylindricalHistogram.vue 6.2 KB

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