zoukankan      html  css  js  c++  java
  • ECharts绘制中国地图、广西地图

    准备工作:导入ECharts依赖、和地图需要的.js文件。

    文件获取方式:

    • 官网:url
    • github:url
      (下载完后 :incubator-echarts-4.8.0mapjsprovince目录下有各个省级的.js文件)

    绘制中国地图

    先在html中添加一个地图要挂载的节点:china-map

    <body>
    <div class="china-map" id="china-map"></div>
    </body>
    

    js:

    <script>
      var myChart = echarts.init(document.getElementById('china-map'));
        var option = {
            tooltip: {
    //                    show: false //不显示提示标签
                formatter: '{b}', //提示标签格式
                backgroundColor:"#ff7f50",//提示标签背景颜色
                textStyle:{color:"#fff"} //提示标签字体颜色
            },
            series: [{
                type: 'map',
                mapType: 'china',
                label: {
                    normal: {
                        show: true,//显示省份标签
                        textStyle:{color:"#c71585"}//省份标签字体颜色
                    },
                    emphasis: {//对应的鼠标悬浮效果
                        show: true,
                        textStyle:{color:"#800080"}
                    }
                },
                itemStyle: {
                    normal: {
                        borderWidth: .5,//区域边框宽度
                        borderColor: '#009fe8',//区域边框颜色
                        areaColor:"#ffefd5",//区域颜色
                    },
                    emphasis: {
                        borderWidth: .5,
                        borderColor: '#4b0082',
                        areaColor:"#f47920",
                    }
                },
                data:[
                    {name:'广西', selected:true},//广西为选中状态
                    {name:'贵州', selected:true},//贵州为选中状态
                    {name:'云南', selected:true},//云南为选中状态
                    {name:'广东', selected:true},//云南为选中状态
                    {name:'海南', selected:true},//云南为选中状态
                    {name:'湖北', selected:true},//云南为选中状态
                ]
            }],
        };
    
        myChart.setOption(option);
        myChart.on('mouseover', function (params) {
            var dataIndex = params.dataIndex;
            console.log(params);
        });
    </script>
    

    绘制广西地图

    和上面的中国地图类似:

    <body>
     <div class="china-map" id="guangxi-map"></div>
    </body>
    
     var myChart = echarts.init(document.getElementById('guangxi-map'));
        var option = {
            title: {
                text : '广西地图',
                subtext : '各市区显示'
            },
            tooltip: {
    //                    show: false //不显示提示标签
                formatter: '{b}', //提示标签格式
                backgroundColor:"#ff7f50",//提示标签背景颜色
                textStyle:{color:"#fff"} //提示标签字体颜色
            },
            series: [
                {
                    name: '数据名称',
                    type: 'map',
                    mapType: '广西',
                    selectedMode : 'single',
                    label: {
                        normal: {
                            show: true,//显示市区标签
                            textStyle:{color:"#c71585"}//省份标签字体颜色
                        },
                        emphasis: {//对应的鼠标悬浮效果
                            show: true,
                            textStyle:{color:"#800080"}
                        }
                    },
                    itemStyle:{
                        normal: {
                            borderWidth: .5,//区域边框宽度
                            borderColor: '#009fe8',//区域边框颜色
                            areaColor:"#ffefd5",//区域颜色
                        },
                        emphasis: {
                            show:true,
                            borderWidth: .5,
                            borderColor: '#4b0082',
                            areaColor:"#f47920",
                        }
                    },
                    data:[
                        {name:'南宁市', selected:true},//**为选中状态
                        {name:'百色市', selected:true},//**为选中状态
                        {name:'玉林市', selected:true},//**为选中状态
                        {name:'柳州市', selected:true},//**为选中状态
                    ]
                }]
        };
        myChart.setOption(option);
        myChart.on('mouseover', function (params) {
                var dataIndex = params.dataIndex;
                console.log(params);
            });
    

    效果展示:

  • 相关阅读:
    yii模板中常用变量总结
    Yii CDbCriteria的常用方法总结
    Yii框架Yiiapp()的理解
    Yii 中比较常用的rules验证规则记录
    c++,opencv播放视频
    python--输入一组无序的数,排序
    python入门,猜数
    关于爬楼梯问题的斐波那契数列
    获取文件名字,路劲中的某一部分信息
    简单帧差法
  • 原文地址:https://www.cnblogs.com/famine/p/13306697.html
Copyright © 2011-2022 走看看