BarLineChart.vue 3.4 KB

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