map-chart.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. (function () {
  2. Vue.component('map-chart', {
  3. template: '<div class="chart_box" >\
  4. <div :id="chartid" class="chart_box"></div>\
  5. </div>',
  6. props: ['config'],
  7. data: function () {
  8. return {
  9. chartid: _.uniqueId("chart_"),
  10. chart: null,
  11. }
  12. },
  13. mounted: function () {
  14. var that =this;
  15. this.$nextTick(function () {
  16. that.chart = echarts.init(document.getElementById(that.chartid));
  17. that.chart.setOption(defaults); //试着一下
  18. })
  19. },
  20. methods: {
  21. setOption: function (options) {
  22. if(!options)return
  23. var options = $.extend({}, defaults, options);
  24. return options
  25. }
  26. },
  27. watch: {
  28. config: function (data) {
  29. if (data) {
  30. this.chart.setOption(this.setOption(data));
  31. }
  32. }
  33. }
  34. })
  35. var defaults = {
  36. tooltip: {
  37. trigger: 'item',
  38. formatter: '{b}<br/>{c} (p / km2)'
  39. },
  40. visualMap: {
  41. min: 800,
  42. max: 50000,
  43. text:['High','Low'],
  44. realtime: false,
  45. calculable: true,
  46. inRange: {
  47. color: ['#c5ddff','#62a3ff', '#277eff', '#005adc', '#0146ad']
  48. }
  49. },
  50. series: [
  51. {
  52. type: 'map',
  53. mapType: '贵港', // 自定义扩展图表类型
  54. itemStyle:{
  55. normal:{
  56. label:{
  57. show:true,
  58. color: '#fff'
  59. },
  60. borderColor: '#fff',
  61. shadowColor: '#0355ab',
  62. shadowBlur: 10,
  63. shadowOffsetX: 10,
  64. shadowOffsetY: 10
  65. },
  66. emphasis:{
  67. label:{
  68. show:true,
  69. color: '#fff'
  70. }
  71. }
  72. },
  73. data:[
  74. {name: '港北区', value: 20057.34},
  75. {name: '港南区', value: 15477.48},
  76. {name: '桂平市', value: 31686.1},
  77. {name: '平南县', value: 6992.6},
  78. {name: '覃塘区', value: 44045.49}
  79. ],
  80. selectedMode: 'single'
  81. }
  82. ]
  83. }
  84. })()