echarts地图展示

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html>  
<html>  
    <head>  
    <base href="<%=basePath%>">
        <title>ECharts</title>  
        <script src="js/jquery-1.9.1.min.js"></script>  
        <script src="js/echarts.min.js"></script>  
        <script src="js/china.js"></script>  
        <script src="js/taiwan.js"></script> 
        <style>#main {width:1000px; height: 1000px;margin: auto;}</style>  
    </head>  
    <body>  
    <!-- 为ECharts准备一个具备大小(宽高)的Dom -->  
    <div id="main"  ></div>  
      
</body>  
<script type="text/javascript">  
    var myChart = echarts.init(document.getElementById('main')); 
     var option = {  
        tooltip: {  
            trigger: 'item'  
        },  
        legend: {  
            orient: 'vertical',  
        },  
        visualMap : {  
            min: 0,  
            max: 1000,  
            y: 'bottom',  
            color: ['orangered','yellow','lightskyblue'],  
            text: ['高', '低'], // 文本,默认为数值文本  
            calculable: true  
        },  
        toolbox: {  
            show: true,  
            orient: 'vertical',  
            x: 'right',  
            y: 'center',  
            feature: {  
                mark: {  
                    show: true  
                },  
                dataView: {  
                    show: true,  
                    readOnly: false  
                }  
            }  
        },  
        series: [{  
            tooltip: {  
                trigger: 'item',  
            },  
            boom:1.3,
            type: 'map',  
            mapType: 'china',  
            left: 10,  
            selectedMode: 'single',  
            label: {  
                normal: {  
                    show: true,  
                    textStyle: {  
                        fontSize: 9,  
                    }  
                },  
                emphasis: {  
                    show: true,  
                    textStyle: {  
                        fontStyle: 'oblique',  
                        fontSize: 9,  
                    }  
                }  
            },  
            showLegendSymbol: false,  
            data: [{  
                name: '北京',  
                selected: false,  
                //随机产生地图区域块的颜色
                value: Math.round(Math.random() * 1000)  
            }, {  
                name: '天津',  
                selected: false,  
                value: Math.round(Math.random() * 1000)  
            }, {  
                name: '上海',  
                selected: false,  
                value: Math.round(Math.random() * 1000)  
            }, {  
                name: '重庆',  
                selected: false,  
                value: Math.round(Math.random() * 1000)  
            }, {  
                name: '河北',  
                selected: false,  
                value: Math.round(Math.random() * 1000)  
            }, {  
                name: '河南',  
                selected: false,  
                value: Math.round(Math.random() * 1000)  
            }, {  
                name: '云南',  
                selected: false,  
                value: Math.round(Math.random() * 1000)  
            }, {  
                name: '辽宁',  
                selected: false,  
                value: Math.round(Math.random() * 1000)  
            }, {  
                name: '黑龙江',  
                selected: false,  
                value: Math.round(Math.random() * 1000)  
            }, {  
                name: '湖南',  
                selected: false,  
                value: Math.round(Math.random() * 1000)  
            }, {  
                name: '安徽',  
                selected: false,  
                value: Math.round(Math.random() * 1000)  
            }, {  
                name: '山东',  
                selected: false,  
                value: Math.round(Math.random() * 1000)  
            }, {  
                name: '新疆',  
                selected: false,  
                value: Math.round(Math.random() * 1000)  
            }, {  
                name: '江苏',  
                selected: false,  
                value: Math.round(Math.random() * 1000)  
            }, {  
                name: '浙江',  
                selected: false,  
                value: Math.round(Math.random() * 1000)  
            }, {  
                name: '江西',  
                selected: false,  
                value: Math.round(Math.random() * 1000)  
            }, {  
                name: '湖北',  
                selected: false,  
                value: Math.round(Math.random() * 1000)  
            }, {  
                name: '广西',  
                selected: false,  
                value: Math.round(Math.random() * 1000)  
            }, {  
                name: '甘肃',  
                selected: false,  
                value: Math.round(Math.random() * 1000)  
            }, {  
                name: '山西',  
                selected: false,  
                value: Math.round(Math.random() * 1000)  
            }, {  
                name: '内蒙古',  
                selected: false,  
                value: Math.round(Math.random() * 1000)  
            }, {  
                name: '陕西',  
                selected: false,  
                value: Math.round(Math.random() * 1000)  
            }, {  
                name: '吉林',  
                selected: false,  
                value: Math.round(Math.random() * 1000)  
            }, {  
                name: '福建',  
                selected: false,  
                value: Math.round(Math.random() * 1000)  
            }, {  
                name: '贵州',  
                selected: false,  
                value: Math.round(Math.random() * 1000)  
            }, {  
                name: '广东',  
                selected: false,  
                value: Math.round(Math.random() * 1000)  
            }, {  
                name: '青海',  
                selected: false,  
                value: Math.round(Math.random() * 1000)  
            }, {  
                name: '西藏',  
                selected: false,  
                value: Math.round(Math.random() * 1000)  
            }, {  
                name: '四川',  
                selected: false,  
                value: Math.round(Math.random() * 1000)  
            }, {  
                name: '宁夏',  
                selected: false,  
                value: Math.round(Math.random() * 1000)  
            }, {  
                name: '海南',  
                selected: false,  
                value: Math.round(Math.random() * 1000)  
            }, {  
                name: '台湾',  
                selected: false,  
                value: Math.round(Math.random() * 1000)  
            }, {  
                name: '香港',  
                selected: false,  
                value: Math.round(Math.random() * 1000)  
            }, {  
                name: '澳门',  
                selected: false,  
                value: Math.round(Math.random() * 1000)  
            }]  
        }, ],  
    };  
    
    if (option && typeof option === "object") {
    myChart.setOption(option, true);
};  
    myChart.on('click', function (params) { 
    var country = params.name;
var url = "http://localhost:8080/codeflow/event/Hello_bak.jsp";
if(country=="台湾") {
//图表点击链接事件
window.location.href = "http://localhost:8080/codeflow/event/Test2.jsp";
}
    });
</script>  
echarts可以通过使用SVG(可缩放矢量图形)来展示地图图片。SVG是一种基于XML的图像格式,可以实现高质量的矢量图形展示。在echarts中,可以使用SVG来绘制各种地图,包括世界地图、国家地图、省份地图等。 要在echarts展示地图图片,首先需要准备好地图数据和对应的SVG文件。可以通过在echarts官方网站或其他资源网站上下载已经制作好的地图SVG文件。然后,在echarts的配置项中,使用"map"属性指定要使用的地图类型,并将对应的SVG文件路径作为值传入。 以下是一个示例代码,展示如何在echarts展示地图图片: ```javascript // 引入echarts库 import echarts from 'echarts'; // 创建echarts实例 const chart = echarts.init(document.getElementById('chart')); // 地图数据 const mapData = \[ { name: '北京', value: 100 }, { name: '上海', value: 200 }, { name: '广州', value: 150 }, // 其他省份数据... \]; // 地图SVG文件路径 const mapSvgPath = 'path/to/map.svg'; // echarts配置项 const option = { // 设置地图类型为自定义地图 map: 'custom', // 指定使用的SVG文件路径 svg: mapSvgPath, // 其他配置项... series: \[ { type: 'map', mapType: 'custom', data: mapData, }, \], }; // 使用配置项绘制地图 chart.setOption(option); ``` 通过以上代码,可以在echarts展示地图图片。需要注意的是,要根据实际情况修改地图数据和SVG文件路径,以及其他echarts配置项,以满足具体需求。\[1\] #### 引用[.reference_title] - *1* [echarts 地图添加纹理图片](https://blog.csdn.net/pwl124/article/details/124731179)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值