VehicleCarAllocation.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <template>
  2. <div ref="chart" class="item" style="height: 330px; width: 224px" />
  3. </template>
  4. <script>
  5. import * as echarts from 'echarts'
  6. export default {
  7. data() {
  8. return {
  9. chart: null,
  10. timer: '',
  11. dataList: [],
  12. }
  13. },
  14. props: {
  15. allocationList: {
  16. type: Array,
  17. default: [],
  18. },
  19. },
  20. // watch: {
  21. // allocationList: {
  22. // handler(val) {
  23. // this.$nextTick(() => {
  24. // const chartDom = this.$refs.chart
  25. // // 初始化图表实例
  26. // this.chart = echarts.init(chartDom)
  27. // this.initChart(val)
  28. // })
  29. // },
  30. // immediate: true,
  31. // deep: true,
  32. // },
  33. // },
  34. methods: {
  35. initChart() {
  36. const option = {
  37. color: ['#1089E7', '#F57474', '#56D0E3', '#F8B448', '#8B78F6', '#B68016'], // 设置柱状图的颜色
  38. // textStyle: {
  39. // color: '#fff',
  40. // fontSize: 16,
  41. // },
  42. tooltip: {
  43. formatter: function (params) {
  44. // console.log(11111111);
  45. // console.log('--------连', params)
  46. return params[0].name + ' : ' + params[1].data
  47. },
  48. trigger: 'axis',
  49. axisPointer: {
  50. type: 'line',
  51. },
  52. },
  53. grid: {
  54. left: '-24%',
  55. right: '4%',
  56. bottom: '0%',
  57. top: '5%',
  58. containLabel: true,
  59. },
  60. xAxis: {
  61. type: 'value',
  62. // 设置x轴显示几段
  63. // min: 0,
  64. max: () => Math.max(...this.allocationList.map(item => item.value)),
  65. interval: 0,
  66. axisTick: { show: false },
  67. axisLine: {
  68. lineStyle: {
  69. color: 'transparent',
  70. },
  71. },
  72. },
  73. yAxis: {
  74. type: 'category',
  75. axisLabel: {
  76. verticalAlign: 'top',
  77. align: 'left',
  78. padding: [-25, 0, 40, 6],
  79. textStyle: {
  80. fontSize: 14,
  81. color: '#1089E7',
  82. // fontFamily: 'Source Han Sans CN',
  83. },
  84. },
  85. data: this.allocationList.map((item) => {
  86. return item.name
  87. }),
  88. axisTick: { show: false },
  89. axisLine: {
  90. show: false,
  91. lineStyle: {
  92. color: '#e0e0e0',
  93. },
  94. },
  95. inside: true,
  96. // textStyle: {
  97. // color: '#000',
  98. // },
  99. },
  100. series: [
  101. {
  102. type: 'bar',
  103. itemStyle: {
  104. color: '#739FA8', // 定义柱形的背景色
  105. borderRadius: [10, 10, 10, 10], //定义背景柱形的圆角
  106. },
  107. barGap: '-100%', //设置柱形重合的重要步骤
  108. data:this.allocationList.map((item) => {
  109. return item.total
  110. }),
  111. animation: false, // 关闭动画效果
  112. barWidth: '18px', // 设置柱形宽度
  113. },
  114. {
  115. type: 'bar',
  116. data: this.allocationList.map((item) => {
  117. return item.value
  118. }),
  119. barWidth: '15px',
  120. barGap: '-90%', //设置柱形重合的重要步骤
  121. itemStyle: {
  122. borderRadius: [10, 10, 10, 10], // 定义柱形的圆角
  123. color: function (params) {
  124. var colorList = ['#1089E7', '#F57474', '#56D0E3', '#F8B448', '#8B78F6', '#B68016','#33FA8F']
  125. return colorList[params.dataIndex]
  126. },
  127. },
  128. },
  129. ],
  130. }
  131. this.chart.setOption(option)
  132. //自适应图表
  133. window.onresize = this.chart.resize
  134. },
  135. },
  136. mounted() {
  137. const chartDom = this.$refs.chart
  138. // console.log('------', chartDom)
  139. // // 初始化图表实例
  140. this.chart = echarts.init(chartDom)
  141. this.initChart()
  142. },
  143. }
  144. </script>
  145. <style scoped lang="less"></style>