yangle
2023-10-18 6d49ec57450e4549ba3ff195526bd17d09a2c98f
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
<!DOCTYPE html>
<html lang="zh-cn">
 
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>浙江地图</title>
 
 
</head>
 
<body>
    <div id="zhejiangmap"></div>
 
 
</body>
 
</html>
<script src="js/jquery.min.js"></script>
<script src='js/echarts.min.js'></script>
<script>
    $("#zhejiangmap").height($(window).height() - 0);
    $(function () {
 
 
        var myChart = echarts.init(document.getElementById('chinamap'));
        chinadatas(myChart);
        //根据窗口的大小变动图表 --- 重点
        window.onresize = function () {
            myChart.resize();
        }
    })
    function chinadatas(myChart) {
        let mapJsonPath = "";
        mapJsonPath = "./json/浙江省.geoJson";
        $.get(mapJsonPath, function (mapJson) {
            echarts.registerMap("chosenMap", mapJson);
            let option = {
                series: [
                    {
                        name: this.selCity,
                        type: "map",
                        mapType: "chosenMap", // 自定义扩展图表类型
                        label: {
                            show: true,
                        },
                    },
                ],
            };
            console.log(that);//问什么此处为that,之前的文章中有写过
            that.mychart.setOption(option);
        });
 
    }
 
 
 
 
</script>