index.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. // 线图
  2. import * as echarts from '../../ec-canvas/echarts';
  3. Component({
  4. properties: {
  5. canvasId: {
  6. type: String,
  7. value: "mychart-dom-bar"
  8. },
  9. id: {
  10. type: String,
  11. value: "mychart-bar"
  12. },
  13. list: {
  14. type: Array,
  15. value: []
  16. }
  17. },
  18. chart: undefined,
  19. ready() {
  20. this.getJSON().then(data => {
  21. this.setData({
  22. show: true,
  23. json: data,
  24. ec: {
  25. onInit: this.initChart.bind(this)
  26. }
  27. })
  28. })
  29. },
  30. // 销毁组件
  31. detached: function () {
  32. this.chart && this.chart.dispose && this.chart.dispose();
  33. },
  34. /**
  35. * 组件的初始数据
  36. */
  37. data: {
  38. show: false,
  39. json: {},
  40. ec: {
  41. onInit: undefined,
  42. },
  43. },
  44. /**
  45. * 组件的方法列表
  46. */
  47. methods: {
  48. getJSON: function () {
  49. return new Promise((reslove, reject) => {
  50. wx.request({
  51. url: 'https://bigdata.smcic.net/data/map_china.json',
  52. success: function (res) {
  53. reslove(res.data)
  54. },
  55. fail: function (err) {
  56. reject(err)
  57. }
  58. })
  59. })
  60. },
  61. initChart: function (canvas, width, height, dpr) {
  62. this.chart && this.chart.dispose && this.chart.dispose();
  63. this.chart = echarts.init(canvas, null, {
  64. width: wx.getSystemInfoSync().windowWidth,
  65. height: 400,
  66. devicePixelRatio: dpr // 像素
  67. });
  68. echarts.registerMap('china', this.data.json);
  69. let max = this.data.list[0][0].value - 0;
  70. var option = {
  71. tooltip: {
  72. show: false,
  73. formatter: "{b}:{c}%"
  74. },
  75. visualMap: {
  76. show: false,
  77. min: 0,
  78. max: max,
  79. inRange: {
  80. color: ['rgba(118,172,255, .2)', 'yellow']
  81. }
  82. },
  83. series: [
  84. {
  85. type: "map",
  86. mapType: "china",
  87. geoIndex: 0,
  88. zppm: 1.25,
  89. label: {
  90. normal: {
  91. show: false
  92. },
  93. emphasis:{
  94. show: false
  95. }
  96. },
  97. scaleLimit: {
  98. //滚轮缩放的极限控制
  99. min: 1.25,
  100. max: 2,
  101. },
  102. itemStyle: {
  103. normal: {
  104. borderColor: "#76acff",//每个区域的边框色
  105. areaColor: 'rgba(118,172,255, 0)'//区域背景色
  106. },
  107. },
  108. data: this.data.list[0] || []
  109. }
  110. ]
  111. };
  112. this.chart.setOption(option);
  113. return this.chart;
  114. }
  115. }
  116. })