BarLineChart.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <template>
  2. <ve-histogram
  3. :id="id"
  4. :height="options.height"
  5. :colors="options.colors"
  6. :data="datas"
  7. :settings="options.settings"
  8. :after-config="options.config"
  9. :after-set-option="extend"
  10. :extend="defaultOptions"
  11. >
  12. </ve-histogram>
  13. </template>
  14. <script>
  15. export default {
  16. name: 'chart',
  17. props: {
  18. id: String,
  19. datas: Object,
  20. options: {
  21. height: String,
  22. colors: Array || Object,
  23. settings: Object,
  24. config: Function
  25. }
  26. },
  27. data () {
  28. return {
  29. defaultOptions: {
  30. grid: {
  31. top: 20
  32. },
  33. xAxis: {
  34. axisLabel: {
  35. margin: 10,
  36. interval: 0, // 强制显示x轴所有刻度
  37. fontSize: 12
  38. },
  39. nameLocation: 'start',
  40. nameTextStyle: {
  41. fontSize: 12,
  42. align: 'left',
  43. padding: [70, 0, 0, 50],
  44. color: '#9B9CA3'
  45. }
  46. },
  47. yAxis (item) {
  48. item[0].splitLine = {
  49. lineStyle: {
  50. type: 'dashed',
  51. width: 0.5
  52. }
  53. }
  54. item[0].axisLabel = {
  55. margin: 2,
  56. fontSize: 12
  57. }
  58. item[1].splitLine = {
  59. show: false
  60. }
  61. item[1].axisLabel = {
  62. show: false,
  63. fontSize: 12
  64. }
  65. return item
  66. },
  67. tooltip: {
  68. trigger: 'axis',
  69. confine: true,
  70. backgroundColor: '#fff',
  71. axisPointer: {
  72. type: 'shadow',
  73. shadowStyle: {
  74. color: 'rgba(42, 190, 209,0.1)'
  75. },
  76. z: 3
  77. },
  78. textStyle: {
  79. color: '#171826',
  80. fontSize: 12
  81. },
  82. padding: [7, 12],
  83. extraCssText: 'box-shadow: 0px 4px 16px rgba(8, 31, 38, 0.08);transform: translate3d(0,0,0)'
  84. },
  85. legend: {
  86. orient: 'horizontal',
  87. icon: 'circle',
  88. bottom: 0,
  89. align: 'left',
  90. itemWidth: 8,
  91. itemHeight: 8,
  92. itemGap: 20,
  93. textStyle: {
  94. fontSize: 12,
  95. rich: {
  96. a: {
  97. fontSize: 16,
  98. verticalAlign: 'top',
  99. align: 'center',
  100. padding: [0, 15, 28, 0]
  101. },
  102. b: {
  103. fontSize: 14,
  104. align: 'center',
  105. padding: [0, 15, 0, 0],
  106. lineHeight: 25
  107. }
  108. }
  109. },
  110. formatter: (name) => {
  111. if (name === '企业数量') {
  112. name = name + '(个)'
  113. }
  114. return name
  115. }
  116. }
  117. }
  118. }
  119. },
  120. computed: {},
  121. watch: {},
  122. mounted () {
  123. console.log(this.datas)
  124. },
  125. methods: {
  126. extend (chart) {
  127. chart.setOption({
  128. series: [{
  129. type: 'bar',
  130. barWidth: 20
  131. }, {
  132. type: 'line',
  133. smooth: false,
  134. symbol: 'none'
  135. }]
  136. })
  137. }
  138. },
  139. beforeDestroy () {}
  140. }
  141. </script>
  142. <style lang="scss" scoped>
  143. </style>