Echarts实战案例代码(39):地理坐标整体地图背景色渐变效果和字体随地图缩放的解决方案

项目需求:
在echarts地图上实现整体的渐变效果。

属性分析:

areaColor: {}

在这里插入图片描述

线性渐变

        itemStyle: {
            normal: {
                borderColor: 'rgba(147, 235, 248, 0.6)',
                borderWidth: 0.8,
                areaColor: {
                    type: 'linear-gradient',
                    x: 0,
                    y: 1500,
                    x2: 1000,
                    y2: 0,
                    colorStops: [{
                        offset: 0.5,
                        color: '#277aec' // 0% 处的颜色
                    }, {
                        offset: 1,
                        color: '#FF0033' // 100% 处的颜色
                    }],
                    global: true // 缺省为 false
                },
            },
            emphasis: {
                areaColor: 'rgba(147, 235, 248, 0)'
            }
        },

字体缩放

var myZoom;
myChart.on('georoam', function(params) {
    if (params.dy || params.dx) {
        return;
    }
    var _zoom = myChart.getOption().geo[0].zoom;
    if (myZoom == _zoom) {
        return;
    }
    option = myChart.getOption();
    if (_zoom > myZoom) {
        option.legend.selected = tempLegend;
        var fontSize = option.series[0].label.fontSize;
        if (fontSize + 1 > 26) {
            option.series[0].label.fontSize = 26;
        } else {
            option.series[0].label.fontSize = fontSize + 1;
        }
        myChart.setOption(option);
    } else {
        var fontSize = option.series[0].label.fontSize;
        if (fontSize - 1 < 12) {
            option.series[0].label.fontSize = 12;
        } else {
            option.series[0].label.fontSize = fontSize - 1;
        }
        myChart.setOption(option);
    }
    myZoom = _zoom;
});

整体代码

option = {
    backgroundColor: 'rgba(0, 10, 52, 1)',
    series: [{
        type: 'map',
        map: 'china',
        tooltip: {
            show: false
        },
        label: {
            show: true,
            color: '#FFFFFF',
            fontSize: 16
        },
        aspectScale: 0.75,
        layoutCenter: ["50%", "50%"], //地图位置
        layoutSize: '100%',
        roam: true,
        geoIndex: 0,
        itemStyle: {
            normal: {
                borderColor: 'rgba(147, 235, 248, 0.6)',
                borderWidth: 0.8,
                areaColor: {
                    type: 'linear-gradient',
                    x: 0,
                    y: 1500,
                    x2: 1000,
                    y2: 0,
                    colorStops: [{
                        offset: 0.5,
                        color: '#277aec' // 0% 处的颜色
                    }, {
                        offset: 1,
                        color: '#FF0033' // 100% 处的颜色
                    }],
                    global: true // 缺省为 false
                },
            },
            emphasis: {
                areaColor: 'rgba(147, 235, 248, 0)'
            }
        },
        zlevel: 1
    }]
};

Done!

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

漏刻有时

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值