Complex histograms.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. <!-- 圆柱柱状图 -->
  2. <template>
  3. <div class="oblongBox" :style="{height:barHeight}">
  4. <boxTop :title="title"/>
  5. <div class="chartsdom" :id="id">
  6. </div>
  7. </div>
  8. </template>
  9. <script>
  10. import boxTop from '@/components/boxTop/index.vue'
  11. export default {
  12. data() {
  13. return {
  14. option: null,
  15. information: {},
  16. }
  17. },
  18. components: {
  19. boxTop,
  20. },
  21. props: {
  22. id: {
  23. type: String,
  24. default: ``,
  25. },
  26. barHeight: {
  27. type: String,
  28. default: `200px`,
  29. },
  30. area: {
  31. type: Array,
  32. },
  33. dataArray: {
  34. type: Array,
  35. },
  36. title: {
  37. type: String,
  38. default: ``,
  39. },
  40. unit: {
  41. type: String,
  42. },
  43. },
  44. mounted() {
  45. this.getEchart()
  46. },
  47. watch: {
  48. dataArray() {
  49. this.getEchart()
  50. },
  51. },
  52. methods: {
  53. getEchart() {
  54. let myChart = echarts.init(document.getElementById(this.id))
  55. let data = {
  56. data: [
  57. [92, 0, 8, 143, 89, 67, 0, 0],
  58. [12, 0, 8, 14, 23, 44, 0, 0],
  59. ],
  60. color: [["#00FFE3", "#4693EC"], ["#1B92FF", "#1B92FF"]],
  61. xAxis: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月'],
  62. legend: ["今年当月", "去年当月"],
  63. };
  64. let series = data.data.map((item, index) => {
  65. return {
  66. name: data.legend[index],
  67. type: 'bar',
  68. itemStyle: {
  69. normal: {
  70. color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
  71. {
  72. offset: 0,
  73. color: data.color[index][0]
  74. },
  75. {
  76. offset: 1,
  77. color: data.color[index][1]
  78. }
  79. ])
  80. }
  81. },
  82. data: data.data[index]
  83. }
  84. })
  85. this.option = {
  86. xAxis: {
  87. axisLabel: {
  88. color: '#29d0d0'
  89. },
  90. type: 'category',
  91. data: data.xAxis
  92. },
  93. legend: {
  94. show: true,
  95. textStyle: {
  96. color: '#ffffff'//字体颜色
  97. }
  98. },
  99. tooltip: {
  100. show: true,
  101. trigger: 'axis',
  102. axisPointer: {
  103. label: {
  104. show: true,
  105. },
  106. },
  107. },
  108. grid: {
  109. top: '15%',
  110. left: '5%',
  111. right: '5%',
  112. bottom: '15%',
  113. containLabel: true
  114. },
  115. yAxis: {
  116. type: 'value'
  117. },
  118. series: series
  119. }
  120. myChart.setOption(this.option, true)
  121. },
  122. },
  123. }
  124. </script>
  125. <style lang="less" scoped>
  126. .oblongBox {
  127. width: 460px;
  128. height: 216px;
  129. background: linear-gradient(rgba(0, 32, 77, 0.8) 0%, rgba(0, 32, 77, 0.5) 100%);
  130. box-shadow: inset 0px 0px 20px 0px rgba(27, 146, 255, 0.3);
  131. .chartsdom {
  132. position: relative;
  133. width: 100%;
  134. height: 90%;
  135. }
  136. .title {
  137. position: absolute;
  138. top: 20px;
  139. left: 30px;
  140. display: flex;
  141. align-items: center;
  142. .label {
  143. font-weight: 500;
  144. font-size: 16px;
  145. color: #FFFFFF;
  146. margin: 0 12px;
  147. }
  148. .value {
  149. font-weight: bold;
  150. font-size: 24px;
  151. background: linear-gradient(0deg, rgba(27, 146, 255, 1) 0%, rgba(255, 255, 255, 1) 50%);
  152. background-clip: text;
  153. -webkit-background-clip: text;
  154. -webkit-text-fill-color: transparent;
  155. }
  156. }
  157. }
  158. </style>