123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- // 线图
- import * as echarts from '../../ec-canvas/echarts';
- Component({
- properties: {
- canvasId: {
- type: String,
- value: "mychart-dom-bar"
- },
- id: {
- type: String,
- value: "mychart-bar"
- },
- list: {
- type: Array,
- value: []
- }
- },
- chart: undefined,
- ready() {
- this.getJSON().then(data => {
- this.setData({
- show: true,
- json: data,
- ec: {
- onInit: this.initChart.bind(this)
- }
- })
- })
- },
- // 销毁组件
- detached: function () {
- this.chart && this.chart.dispose && this.chart.dispose();
- },
- /**
- * 组件的初始数据
- */
- data: {
- show: false,
- json: {},
- ec: {
- onInit: undefined,
- },
- },
- /**
- * 组件的方法列表
- */
- methods: {
- getJSON: function () {
- return new Promise((reslove, reject) => {
- wx.request({
- url: 'https://bigdata.smcic.net/data/map_china.json',
- success: function (res) {
- reslove(res.data)
- },
- fail: function (err) {
- reject(err)
- }
- })
- })
- },
- initChart: function (canvas, width, height, dpr) {
- this.chart && this.chart.dispose && this.chart.dispose();
- this.chart = echarts.init(canvas, null, {
- width: wx.getSystemInfoSync().windowWidth,
- height: 400,
- devicePixelRatio: dpr // 像素
- });
- echarts.registerMap('china', this.data.json);
- let max = this.data.list[0][0].value - 0;
- var option = {
- tooltip: {
- show: false,
- formatter: "{b}:{c}%"
- },
- visualMap: {
- show: false,
- min: 0,
- max: max,
- inRange: {
- color: ['rgba(118,172,255, .2)', 'yellow']
- }
- },
- series: [
- {
- type: "map",
- mapType: "china",
- geoIndex: 0,
- zppm: 1.25,
- label: {
- normal: {
- show: false
- },
- emphasis:{
- show: false
- }
- },
- scaleLimit: {
- //滚轮缩放的极限控制
- min: 1.25,
- max: 2,
- },
- itemStyle: {
- normal: {
- borderColor: "#76acff",//每个区域的边框色
- areaColor: 'rgba(118,172,255, 0)'//区域背景色
- },
- },
- data: this.data.list[0] || []
- }
- ]
- };
- this.chart.setOption(option);
- return this.chart;
- }
- }
- })
|