熱力圖heatmap使用


參考:https://www.cnblogs.com/julinhuitianxia/p/7755246.html

1.首先到echarts官網下載應用實例:http://echarts.baidu.com/examples/editor.html?c=heatmap-bmap

2.在A頁面中用iframe標簽進行跳轉(使用該方法的原因:如果你的主頁面有應用到其他版本的echarts或jQuery話可能會因為echarts或jQuery版本問題一直報錯,如果單純僅僅使用熱力圖的話可以直接使用)

3.heatmap-bmap.html頁面 

<!DOCTYPE html>
<html style="height: 100%">
   <head>
       <meta charset="utf-8">
   </head>
   <body style="height: 100%; margin: 0">
       <div id="container" style="height: 100%"></div>
      <!--引用jQuery-->
      <script type="text/javascript" src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>

       <script type="text/javascript" src="../../../script/plugin/jquery/jquery.cookie.js"></script>
       <script type="text/javascript" src="http://echarts.baidu.com/gallery/vendors/echarts/echarts.min.js"></script>
       <script type="text/javascript" src="http://echarts.baidu.com/gallery/vendors/echarts-gl/echarts-gl.min.js"></script>
       <script type="text/javascript" src="http://echarts.baidu.com/gallery/vendors/echarts-stat/ecStat.min.js"></script>
       <script type="text/javascript" src="http://echarts.baidu.com/gallery/vendors/echarts/extension/dataTool.min.js"></script>
       <script type="text/javascript" src="http://echarts.baidu.com/gallery/vendors/echarts/map/js/china.js"></script>
       <script type="text/javascript" src="http://echarts.baidu.com/gallery/vendors/echarts/map/js/world.js"></script>
       <script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=ZUONbpqGBsYGXNIYHicvbAbM"></script>
       <script type="text/javascript" src="http://echarts.baidu.com/gallery/vendors/echarts/extension/bmap.min.js"></script>
       <script type="text/javascript" src="http://echarts.baidu.com/gallery/vendors/simplex.js"></script>

       <script type="text/javascript">
           var dom = document.getElementById("container");
            var myChart = echarts.init(dom);
            var app = {};
            option = null;
            var lon ='';
            var lat ='';
            app.title = '熱力圖與百度地圖擴展';
            $.ajax({
                type: 'POST',
                url: '../../../baseinfo/demoCounty/queryHotMapData.do',
                data: {'county':$.cookie('defaultCounty')},
                cache: false,
                success: function (da) {
                    var arr = da.opInfo.hotMapData;
                    var data =[];
                    lon=arr[0].LON;
                    lat=arr[0].LAT;
                    for(var i=0;i<arr.length;i++){
                        var coord=[]
                        coord.push(arr[i].LON);coord.push(arr[i].LAT);coord.push(1) ;
                        data.push(coord)
                    }
                    myChart.setOption(option = {
                        animation: false,
                        bmap: {
                            center: [lon, lat],
                            zoom: 10,   //地圖比例尺,調節地圖初始化時候的大小
                            roam: true
                        },
                        visualMap: {
                            show: false,
                            top: 'top',
                            min: 0,
                            max: 5,
                            seriesIndex: 0,
                            calculable: true,
                            inRange: {
                                color: ['blue', 'blue', 'green', 'yellow', 'red']
                            }
                        },
                        series: [{
                            type: 'heatmap',
                            coordinateSystem: 'bmap',
                            data: data,
                            pointSize: 5,
                            blurSize: 6
                        }]
                    });
                    if (!app.inNode) {
                        // 添加百度地圖插件
                        var bmap = myChart.getModel().getComponent('bmap').getBMap();
                        bmap.addControl(new BMap.MapTypeControl());
                    }
                },
                dataType: "json",
                error: function (er) {
                }
            });

            if (option && typeof option === "object") {
                myChart.setOption(option, true);
            }
       </script>
   </body>
</html>

 


注意!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系我们删除。



 
粤ICP备14056181号  © 2014-2021 ITdaan.com