统计组合图:实例三

63 篇文章 1 订阅
54 篇文章 1 订阅

在这里插入图片描述

index.blade.php

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>地图界面</title>
    <link rel="stylesheet" href="./eslydsj/js/bstable/css/bootstrap.min.css">
    <link rel="stylesheet" href="./eslydsj/js/jQueryPage/src/jquery.page.css">
    <link rel="stylesheet" href="./eslydsj/css/base.css">
    {{--<script src="http://www.jq22.com/jquery/jquery-1.10.2.js"></script>--}}
    {{--<script type="text/javascript" src="https://cdn.bootcss.com/echarts/4.2.0-rc.2/echarts.min.js"></script>--}}
    <script type="text/javascript" src="./vendor/echarts-china-map/js/jquery.min.js"></script>
    <script type="text/javascript" src="./vendor/echarts-china-map/js/echarts-4.2.0-rc.min.js"></script>
    <script type="text/javascript" src="./vendor/echarts-china-map/js/map/china.js"></script>
    <script type="text/javascript" src="./js/web/china-map.js"></script>
    <style>
        #china-map {
            width: 100%;
            height: 93vh;
        }
        .order_list{
            margin: 10px;
            color: #FFF;
        }
        .order_list td{
            font-size: 2rem;
            line-height: 40px;
        }
        .order_list td:first-child{
            color: #17ccde;
        }
        .order_1{color: #00e765;text-align: right}
        .order_2{color: #07A3AD;text-align: right}
        .col-md-3{padding:0 5px 0 0; }

        .chejian{
            border: none;
            background: none;
            color: #FFF;
            padding-left: 0;
            font-size: 1.5rem;
        }
    </style>
</head>
<body>
<!--顶部-->
<header class="header left">
    <div class="left nav">
        <ul>

        </ul>
    </div>
    <div class="header_center left">
        <h2><strong class="all_base">全国</strong><strong>-</strong><strong class="all_factory">全工厂</strong><strong>员工分布</strong></h2>
        {{--<p class="color_font"><small>Comprehensive service platform for smart tourism</small></p>--}}
    </div>
    <div class="right nav text_right">

    </div>

</header>
<!--内容部分-->
<div class="map_con left" id="car_control" >
    <!--左侧地图-->
    <div class="left map_left" >
        {{--<button id="back">返回全国</button>--}}
        <div style="z-index: 999;width:30%;position: absolute;top: 10%;left: 1%;">
            <div class="row">
                <div class="form-group">
                    <div class="col-md-3" style="width: 105px">
                        <div id="back" class="form-control btn btn-default" style="display: none"><i class="glyphicon glyphicon-chevron-left"></i> 返回</div>
                    </div>
                    <div class="col-md-3">
                        <select name="provincesList" id="provincesList" class="form-control" >
                            <option value="0">全国</option>
                            @foreach($area as $k => $v)
                                <option value="{{ $k }}">{{ $v }}</option>
                            @endforeach
                        </select>
                    </div>
                    <div class="col-md-3">
                        <select name="factoryList" id="factoryList" class="form-control">
                            <option value="0">全工厂</option>
                        </select>
                    </div>
                </div>
            </div>
            <div class="row" style="margin-top: 10px">
                <div class="col-md-3">
                    <div class="col-md-2" style="padding: 0"><input type="checkbox" name="chefeng" value="1" class="chefeng form-control"></div>
                    <div class="col-md-10"><span class="form-control chejian">车缝车间</span></div>
                </div>
            </div>
            <div class="row" style="margin-top: 10px">
                <div class="col-md-3">
                    <div class="col-md-2" style="padding: 0"><input type="checkbox" name="houzheng" value="1" class="houzheng form-control"></div>
                    <div class="col-md-10"><span class="form-control chejian">后整车间</span></div>
                </div>
            </div>
            <div class="row" style="margin-top: 10px">
                <div class="col-md-3">
                    <div class="col-md-2" style="padding: 0"><input type="checkbox" name="caijian" value="1" class="caijian form-control"></div>
                    <div class="col-md-10"><span class="form-control chejian">裁剪车间</span></div>
                </div>
            </div>
        </div>

        <div id="china-map" ></div>
    </div>
    <!--右侧功能栏-->
    <div class="right map_right">
        <div class="map_con" style="height: 93vh;">
            <div class="order_list">
                <div class="person_list">
                </div>
            </div>
        </div>
    </div>
</div>

<script>
    var initLevel = 1;
    var initpName = 'china';
    var initChinese_ = '';
    var initCode = '';
    var initKey = 0;
    var cfStatus,hzStatus,cjStatus = false;


    var myChart = echarts.init(document.getElementById('china-map'));
    initEcharts("china", "中国",1);

    var mapFeatures = echarts.getMap(initpName).geoJson.features;
    myChart.hideLoading();
    var geoCoordMap = {};
    mapFeatures.forEach(function(v) {
        // 地区名称
        var name = v.properties.name;
        // 地区经纬度
        geoCoordMap[name] = v.properties.cp;
    });

    // 初始化echarts
    function initEcharts(pName, Chinese_, type) {
        var provincesKey = $('#provincesList').val()
        var factoryKey = $('#factoryList').val()
        var data = {
            provincesKey: provincesKey,
            factoryKey: factoryKey,
            cfStatus: cfStatus,
            hzStatus: hzStatus,
            cjStatus: cjStatus,
            type:type,
            proCode:initCode,
        };
        $.ajax({
            url:'{{ route('getMapsList') }}',
            data:data,
            type:'GET',
            success:function(data) {
                tmpSeriesData = data
                initPerson(tmpSeriesData)
                var option = {
                    tooltip: {
                        show: true,
                        formatter: function(params) {
                            if (params.data) return params.name + ':' + params.data['value'] + '人'
                        },
                    },
                    visualMap: {
                        type: 'continuous',
                        text: ['', ''],
                        showLabel: true,
                        left: '50',
                        min: 0,
                        max: 100,
                        inRange: {
                            color: [ '#ffffff', '#af8e81', '#c19c80', '#d99282', ]
                        },
                        splitNumber: 0
                    },
                    geo: {
                        show: true,
                        name: Chinese_ || pName,
                        label: {
                            normal: {
                                show: false
                            },
                            emphasis: {
                                show: false,
                            }
                        },
                        roam: true,
                        itemStyle: {
                            normal: {
                                areaColor: '#031525',
                                borderColor: '#3B5077',
                            },
                            emphasis: {
                                areaColor: '#2B91B7',
                            }
                        }
                    },
                    series: [
                        {
                            name: Chinese_ || pName,
                            type: 'map',
                            mapType: pName,
                            roam: false,//是否开启鼠标缩放和平移漫游
                            data: tmpSeriesData,
                            zoom:1.2,
                            selectedMode: false,//是否允许选中多个区域
                            label: {
                                normal: {
                                    show: true,
                                    formatter:function(val){
                                        if(val.value > 0){
                                            var area_content =  '{a|' + val.name + '}' + '-' + '{b|' + val.value + '}';
                                            return area_content.split("-").join("\n");
                                        }
                                    },//让series 中的文字进行换行
                                    rich: {
                                        a: {
                                            color: '#1b99cd',
                                            fontSize: 14,
                                            fontWeight:'bold',
                                            width: 16,
                                            height: 16,
                                        },
                                        b: {
                                            color: '#8d003b',
                                            fontFamily: 'Microsoft YaHei',
                                            fontSize: 14,
                                            width: 16,
                                            height: 16,
                                            textAlign: 'center',
                                            padding: 2,
                                        }
                                    },//富文本样式,就是上面的formatter中'{a|'和'{b|'
                                },
                            },//地图中文字内容及样式控制
                            itemStyle: {
                                normal: {
                                    borderWidth: .1,//区域边框宽度
                                    borderColor: '#0550c3',//区域边框颜色
                                    areaColor:"#4ea397",//区域颜色

                                },
                                emphasis: {
                                    borderWidth: .1,
                                    borderColor: '#4b0082',
                                    areaColor:"#ece39e",
                                }
                            },
                        },
                    ]
                };
                myChart.setOption(option);
                myChart.off("click");
                if (pName === "china") { // 全国时,添加click 进入省级
                    myChart.on('click', function (param) {
                        // 遍历取到provincesText 中的下标  去拿到对应的省js
                        for (var i = 0; i < provincesText.length; i++) {
                            if (param.name === provincesText[i]) {
                                initKey = i;
                                //显示对应省份的方法
                                initLevel = 2;
                                initpName = provinces[i];
                                initChinese_ = provincesText[i];
                                initCode = provincesCode[i];
                                showProvince(initpName, initChinese_,2, initCode);
                                break;
                            }
                        }
                        if (param.componentType === 'series') {
                            var provinceName =param.name;
                            $('#box').css('display','block');
                            $("#box-title").html(provinceName);
                        }
                    });
                }else{
                    $('#back').show();
                }
                // else {
                //     // 省份,添加双击 回退到全国
                //     myChart.on('dblclick', function(params) {
                //         initLevel = 1
                //         goInitEcharts();
                //         //显示对应省份的方法
                //
                //     });
                // }
            }
        });
    }
    // 展示对应的省
    function showProvince(pName, Chinese_,type,proCode) {
        initLevel = 2;
        initpName = pName;
        initChinese_ = Chinese_;
        //这写省份的js都是通过在线构建工具生成的,保存在本地,需要时加载使用即可,最好不要一开始全部直接引入。
        loadBdScript('$' + pName + 'JS', './vendor/echarts-china-map/js/map/province/' + pName + '.js', function () {
            initEcharts(Chinese_,pName,type,proCode);
        });
    }
    // 加载对应的JS
    function loadBdScript(scriptId, url, callback) {
        var script = document.createElement("script");
        script.type = "text/javascript";
        if (script.readyState) {  //IE
            script.onreadystatechange = function () {
                if (script.readyState === "loaded" || script.readyState === "complete") {
                    script.onreadystatechange = null;
                    callback();
                }
            };
        } else {  // Others
            script.onload = function () {
                callback();
            };
        }
        script.src = url;
        script.id = scriptId;
        document.getElementsByTagName("head")[0].appendChild(script);
    };

    // 加载省份下拉内容
    $('#provincesList').on('change',function () {
        var all_base = $(this).find('option:selected').text();
        $('.all_base').html(all_base);
        $('.all_factory').html('全工厂');

        $('#factoryList').empty()
        var data = {
            key:$(this).val()
        };
        $.ajax({
            url:'{{ route('getBaseFactory') }}',
            data:data,
            type:'GET',
            success:function(data) {
                var option = "<option value='0'>全工厂</option>";
                for (var i=0; i < data.length; i++){
                    option += "<option value='"+ data[i]['id'] +"'>"+ data[i]['name'] +"</option>";
                }
                $('#factoryList').append(option)
                goInitEcharts();
            }
        });
    })
    $('#factoryList').on('change',function () {
        var factory = $(this).find('option:selected').text();
        $('.all_factory').html(factory);
        goInitEcharts();
    })

    $('#highDepartid').on('change',function () {
        goInitEcharts();
    })
    $('.chefeng').on('change',function () {
        cfStatus = $(this).prop("checked")
        goInitEcharts();
    })
    $('.houzheng').on('change',function () {
        hzStatus = $(this).prop("checked")
        goInitEcharts();
    })
    $('.caijian').on('change',function () {
        cjStatus = $(this).prop("checked")
        goInitEcharts();
    })

    function goInitEcharts(){
        if(initLevel==1){
            initpName = 'china';
            initChinese_ = '';
            initCode = '';
            initKey = 0;
            initLevel =1;
            //返回全国地图
            initEcharts("china", "中国", 1);
        }else{
            showProvince(initpName, initChinese_)
        }
    }
    $('#back').on('click',function () {
        $('#back').hide();
        initpName = 'china';
        initChinese_ = '';
        initCode = '';
        initKey = 0;
        initLevel =1;
        initEcharts("china", "中国", 1);
    });
    //填充明细
    function initPerson(data){
        $('.person_list').empty();
        var html = '';
        var countTotal = 0;
        for(var i=0; i<data.length; i++){
            if(data[i]['value'] > 0){
                html += '<div class="col-md-12" style="padding: 0;font-size: 2rem;line-height: 2.8rem;"><div class="col-md-7" style="padding: 0">'+data[i]['name']+':</div><div class="col-md-5 order_1" style="padding-left: 0;font-size: 2.5rem;font-weight: bold;">'+data[i]['value']+'人</div></div >';
            }
            countTotal += data[i]['value'];
        }
        html += '<div class="col-md-12" style="margin-top: 20px;padding: 0;font-size: 2rem;line-height: 2.8rem;"><div class="col-md-7" style="padding: 0">在职总人数:</div><div class="col-md-5 order_1" style="padding-left: 0;font-size: 2.5rem;font-weight: bold;">'+countTotal+'人</div></div >';
        $('.person_list').append(html);
    }

</script>
</body>
</html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值