MapChart.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. <template>
  2. <ve-map
  3. :height="options.height"
  4. :after-config="options.config"
  5. :data="datas"
  6. :settings="defaultSettings"
  7. :extend="defaultOptions">
  8. </ve-map>
  9. </template>
  10. <script>
  11. const mapJson = require('../../assets/js/china.json')
  12. console.log(mapJson)
  13. export default {
  14. name: 'chart',
  15. props: {
  16. id: String,
  17. datas: Object,
  18. options: {
  19. height: String,
  20. colors: Array || Object,
  21. settings: Object,
  22. config: Function
  23. }
  24. },
  25. data () {
  26. return {
  27. initRendererSvg: {
  28. renderer: 'svg'
  29. },
  30. defaultSettings: {
  31. // positionJsonLink: '/page_big_pc/assets/js/china.json',
  32. mapOrigin: mapJson,
  33. label: {
  34. show: true,
  35. fontSize: 12
  36. },
  37. selectedMode: false, // 去掉省份小圆点
  38. itemStyle: {
  39. normal: {
  40. borderColor: '#F06326',
  41. areaColor: '#FFFFFF'
  42. }
  43. },
  44. mapGrid: {
  45. left: 82,
  46. right: 82
  47. }
  48. },
  49. defaultOptions: {
  50. tooltip: {
  51. confine: true,
  52. backgroundColor: '#fff',
  53. axisPointer: {
  54. type: 'shadow',
  55. shadowStyle: {
  56. color: 'rgba(5,166,243,0.1)'
  57. },
  58. z: 3
  59. },
  60. textStyle: {
  61. color: '#171826',
  62. fontSize: 12
  63. },
  64. padding: [8, 12],
  65. extraCssText: 'box-shadow: 0px 4px 16px rgba(8, 31, 38, 0.08)',
  66. formatter: (params, ticket, callback) => {
  67. if (params.data === null) {
  68. return params.name + ':0'
  69. } else {
  70. return params.name + ':' + params.value
  71. }
  72. }
  73. },
  74. grid: {
  75. left: 32,
  76. right: 16,
  77. containLabel: true
  78. },
  79. legend: {
  80. selectedMode: false,
  81. textStyle: {
  82. color: 'transparent'
  83. },
  84. itemWidth: 0,
  85. itemHeight: 0
  86. },
  87. silent: false, // 禁用鼠标点击、滑过事件
  88. series: {
  89. showLegendSymbol: false,
  90. selectedMode: false
  91. },
  92. graphic: [
  93. {
  94. type: 'group',
  95. bottom: 42,
  96. children: [
  97. {
  98. type: 'text',
  99. z: 100,
  100. left: 'left',
  101. top: 'middle',
  102. style: {
  103. fill: '#333',
  104. text: '市场分布数量',
  105. font: '12px Microsoft YaHei'
  106. }
  107. }]
  108. },
  109. {
  110. type: 'rect',
  111. z: 101,
  112. left: 0,
  113. bottom: 16,
  114. shape: {
  115. width: 150,
  116. height: 24
  117. },
  118. style: {
  119. stroke: '#FB483D',
  120. fill: 'transparent',
  121. lineWidth: 0.5
  122. }
  123. },
  124. this.rectGroup(0, '#F06326'),
  125. this.rectGroup(25, '#F48A5D'),
  126. this.rectGroup(50, '#FFB366'),
  127. this.rectGroup(75, '#FFCF9F'),
  128. this.rectGroup(100, '#FFE7CF'),
  129. this.rectGroup(125, '#FFF4EB'),
  130. {
  131. type: 'group',
  132. width: 150,
  133. bottom: 0,
  134. left: 0,
  135. children: [{
  136. type: 'text',
  137. z: 100,
  138. left: 'left',
  139. top: 'middle',
  140. style: {
  141. fill: '#333',
  142. font: '12px Microsoft YaHei'
  143. }
  144. },
  145. {
  146. type: 'text',
  147. z: 100,
  148. left: 'right',
  149. top: 'middle',
  150. style: {
  151. fill: '#333',
  152. text: '0',
  153. font: '12px Microsoft YaHei'
  154. }
  155. }]
  156. }
  157. ],
  158. visualMap: {
  159. show: false,
  160. inRange: {
  161. color: ['#FFF4EB', '#FFE7CF', '#FFCF9F', '#FFB366', '#F48A5D', '#F06326']
  162. },
  163. outOfRange: {
  164. color: ['#F06326']
  165. }
  166. }
  167. }
  168. }
  169. },
  170. computed: {},
  171. watch: {},
  172. mounted () {},
  173. methods: {
  174. extend (chart) {
  175. chart.setOption({
  176. series: [{
  177. type: 'bar',
  178. barWidth: 20
  179. }, {
  180. type: 'line',
  181. smooth: false,
  182. symbol: 'none'
  183. }]
  184. })
  185. },
  186. rectGroup (left, color) {
  187. return {
  188. type: 'rect',
  189. z: 90,
  190. left: left,
  191. bottom: 16,
  192. shape: {
  193. width: 25,
  194. height: 24
  195. },
  196. style: {
  197. fill: color
  198. }
  199. }
  200. }
  201. },
  202. beforeDestroy () {}
  203. }
  204. </script>
  205. <style lang="scss" scoped>
  206. </style>