当前位置:   article > 正文

echarts地图的使用_echarts.getmap

echarts.getmap
var mapFeatures = echarts.getMap('china').geoJson.features;
let res = []
    mapFeatures.forEach(function (v) {
        // 地区名称
        let name = v.properties.name;
        let value = v.properties.cp;
        value.push(0)
        res.push({name,value})
        // 地区经纬度
        // geoCoordMap[name] = v.properties.cp;
    });
    let max = function (data) {
            return Number(data[0].value)
    }
    let min = function (data) {

        return Number(data[data.length-1].value)
    }
    var convertData = function (data) {
        res.forEach(item=>{
            data.forEach(ite=>{
                if(item.name == ite.name){
                    item.value[2] = ite.value
                }
            })
        })
        return res;
    };












var option = {
        tooltip: {
            trigger: 'item',
            triggerOn:"click",
            confine:true,
            position:"left",
            enterable: true,
            alwaysShowContent: false,
            formatter: function (params) {
                if(type==1){
                    if (params.value==0) {
                        return params.name + ' : ' + 0 + '家';
                    } else {
                        var res = params.name + ':<span style="font-size:22px;color:rgba(122,233,229,1);">' + params.data.value[2] + '</span>家' + '<br/>';
                        res += '<ul class="format-list">'
                        for (var i = 0; i < json.dcqylist.length; i++)
                            if (json.dcqylist[i].name == params.name)
                                res += '<li>' + json.dcqylist[i].DCQY + '</li>'
                        res += '</ul>'
                        return res
                    }
                }else if(type == 2){

                        return params.name + ' : ' + params.data.value[2] + 'GWh';

                }

            },
            textStyle: {
                fontFamily: 'PingFangSC-Regular',
                fontSize: 15,
                lineHeight: 18
            },
            backgroundColor: 'rgba(0,22,30,0.4)',
            borderColor: 'rgba(27, 113, 110, 0.5)',
            borderWidth: '1px',
            padding: [20, 20, 20, 20],
            extraCssText: 'border-radius:2px;'
           
        },
        legend: {
        },
        visualMap: {
            show: true,
            min: min(data),
            max: max(data),
            left: '20%',
            top: 'bottom',
            // text: ['高', '低'], // 文本,默认为数值文本
            seriesIndex: [0],
            inRange: {
                color: ["#48AFC3","#389FB3","#268DA0","#157C8E","#0C7385","#02697B"] // 蓝绿

            },
            textStyle: {
                show:false,
                fontFamily: 'PingFangSC-Regular',
                fontSize: 8,
                lineHeight: 18,
                color:'#fff'
            }
        },
        geo: {
            // regions: [{
            //     name: '广东',
            //     itemStyle: {
            //         areaColor: 'red',
            //         color: 'red'
            //     }
            // }],
            map: 'china',

            zoom:1.2,
            roam: true,
            left:"29%",
            label: {
                normal: {
                    show: false,
                    textStyle: {
                        color: "#e2e2e2",
                        fontSize: 8
                    },

                },
                emphasis: {
                    show: false,
                    textStyle: {
                        color: "#fff"
                    },

                }
            },
            itemStyle: {
                normal: {
                    areaColor: 'rgba(15, 118, 132, 0.9)',
                    color: 'rgba(128, 128, 128, 0)'
                },
                emphasis: {
                    areaColor: 'rgba(239,197,73,0.9)',
                }
            }
        },

        series: [
            {
                type: 'map',
                geoIndex: 0,

                data: convertData(data),
                showLegendSymbol:false,
            },


            {
                type: 'scatter',
                coordinateSystem: 'geo',
                symbol: 'circle', //气泡
                symbolSize: 5,
                label: {
                    normal: {
                        show: true,
                        position:"right",
                        formatter:"{b}",
                        textStyle: {
                            color: "#e2e2e2",
                            fontSize: 8
                        },

                    }
                },
                itemStyle: {
                    normal: {
                        color: '#e2e2e2', //标志颜色
                    }
                },

                data: convertData(data),

            },
        ]
    };
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
  • 141
  • 142
  • 143
  • 144
  • 145
  • 146
  • 147
  • 148
  • 149
  • 150
  • 151
  • 152
  • 153
  • 154
  • 155
  • 156
  • 157
  • 158
  • 159
  • 160
  • 161
  • 162
  • 163
  • 164
  • 165
  • 166
  • 167
  • 168
  • 169
  • 170
  • 171
  • 172
  • 173
  • 174
  • 175
  • 176
  • 177
  • 178
  • 179
  • 180
  • 181
声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop】
推荐阅读