CostHistogram.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. <!--
  2. * @Author: your name
  3. * @Date: 2021-10-12 09:10:42
  4. * @LastEditTime: 2021-10-22 15:49:54
  5. * @LastEditors: Please set LastEditors
  6. * @Description: 成本分析的柱状图
  7. * @FilePath: \hyyfClient\src\views\PdcData\analysis\CostHistogram.vue
  8. -->
  9. <template>
  10. <div class="cost-histogram">
  11. <div id="costHistogram"></div>
  12. </div>
  13. </template>
  14. <script>
  15. export default {
  16. props: {
  17. data: {
  18. type: Array,
  19. default: () => []
  20. }
  21. },
  22. data() {
  23. return {
  24. myChart: null
  25. }
  26. },
  27. methods: {
  28. init() {
  29. let options = {
  30. // title: {
  31. // text: '存栏变动',
  32. // x: 10,
  33. // y: 0
  34. // },
  35. tooltip: {
  36. trigger: 'axis',
  37. },
  38. // legend: {
  39. // data: ['头']
  40. // },
  41. color: ['#3aa0ff', '#4dcb73', '#fad337', '#f2637b', '#975fe4'],
  42. grid: {
  43. left: '3%',
  44. right: '4%',
  45. bottom: '3%',
  46. containLabel: true
  47. },
  48. xAxis: [
  49. {
  50. type: 'value',
  51. name: '元',
  52. boundaryGap: [0, 0.01],
  53. axisPointer: {
  54. type: 'shadow'
  55. },
  56. axisLine: {
  57. show: true,
  58. lineStyle: {
  59. color: '#6e7079',
  60. }
  61. },
  62. axisTick:{
  63. show: false
  64. },
  65. }
  66. ],
  67. yAxis: //[
  68. {
  69. type: 'category',
  70. inverse: true
  71. // axisLabel: {
  72. // // formatter: '{value} °C'
  73. // show: true
  74. // },
  75. // axisLine: {
  76. // show: true,
  77. // lineStyle: {
  78. // color: '#6e7079',
  79. // }
  80. // },
  81. // axisTick:{
  82. // show:false
  83. // },
  84. // splitLine:{
  85. // show:false
  86. // }
  87. },
  88. // {
  89. // type: 'value',
  90. // name: '湿度',
  91. // axisLabel: {
  92. // formatter: '{value} RH'
  93. // },
  94. // axisLine: {
  95. // show: false,
  96. // lineStyle: {
  97. // color: '#6e7079',
  98. // }
  99. // },
  100. // axisTick:{
  101. // show:false
  102. // },
  103. // // splitLine:{
  104. // // show:false
  105. // // }
  106. // }
  107. //],
  108. // dataset: [
  109. // {
  110. // dimensions: ['num'],
  111. // source: [
  112. // [32541],
  113. // [82467],
  114. // [54363],
  115. // [64642],
  116. // [40257],
  117. // [95422]
  118. // ]
  119. // },
  120. // {
  121. // transeform: {
  122. // type: 'sort',
  123. // config: {
  124. // dimension: 'num',
  125. // order: 'desc'
  126. // }
  127. // }
  128. // }
  129. // ],
  130. series: [
  131. {
  132. // name: '头',
  133. type: 'bar',
  134. data: this.data,
  135. itemStyle: {
  136. normal: {
  137. color: function (colors) { // 颜色设置
  138. var colorList = ['rgb(112,182,3)', 'rgb(232,56,92)', 'rgb(123,0,255)', 'rgb(0,215,233)', 'rgb(255,255,160)', 'rgb(0,0,255)']
  139. return colorList[colors.dataIndex]
  140. },
  141. label: {
  142. show: true,
  143. position: 'right'
  144. }
  145. },
  146. textStyle: {
  147. show: true
  148. },
  149. }
  150. }
  151. ]
  152. }
  153. this.myChart.setOption(options);
  154. }
  155. },
  156. mounted() {
  157. this.myChart = this.$echarts.init(document.getElementById('costHistogram'));
  158. // this.init();
  159. },
  160. watch: {
  161. data(value) {
  162. console.log('成本分析柱状图数据', value)
  163. this.init()
  164. }
  165. }
  166. }
  167. </script>
  168. <style scoped>
  169. .cost-histogram {
  170. display: inline-block;
  171. width: 90%;
  172. height: 300px;
  173. }
  174. #costHistogram {
  175. width: 100%;
  176. height: 100%;
  177. }
  178. </style>