search
HomeBackend DevelopmentPHP TutorialPHP+jQuery realizes the statistical display effect of China map hotspot data

PHP+jQuery realizes the statistical display effect of China map hotspot data

An example of China map hotspot data statistical display implemented by PHP jQuery. When the mouse slides to the designated province area on the map, the data information of the corresponding province will be displayed in the pop-up prompt box.

PHP+jQuery realizes the statistical display effect of China map hotspot data

First add a div #tip to the page to display the prompt box for map information and #map to generate the map.

<div id="map"></div>  
<div id="tip"></div>

Then we introduce the jQuery library, raphael.js and chinamapPath.js (China map data)

<script type="text/javascript" src="jquery.js"></script>  
<script type="text/javascript" src="raphael.js"></script> 
<script type="text/javascript" src="chinamapPath.js"></script>

Draw the China map by calling raphael, and then load the statistical data. Due to the map block Xiao, we do not display the data on the map block when the map is loaded. We use mouse interaction to better display the data information to the user.

When the mouse slides to the province block, locate the mouse coordinates through e.clientX and e.clientY, then locate the prompt box div#tip through jquery's css() method, and change the name and name of the corresponding province The number of active users is added to the prompt box and displayed. The code is as follows:

$(function() { 
    $.get("json.php", 
    function(json) { 
        var data = string2Array(json); 
        var flag; 
        var arr = new Array(); 
        for (var i = 0; i < data.length; i++) { 
            var d = data[i]; 
            if (d < 100) { 
                flag = 0; 
            } else if (d >= 100 && d < 500) { 
                flag = 1; 
            } else if (d >= 500 && d < 2000) { 
                flag = 2; 
            } else if (d >= 2000 && d < 5000) { 
                flag = 3; 
            } else if (d >= 5000 && d < 10000) { 
                flag = 4; 
            } else { 
                flag = 5; 
            } 
            arr.push(flag); 
        } 
        var colors = ["#d7eef8", "#97d6f5", "#3fbeef", "#00a2e9", "#0084be", "#005c86"]; 
        var R = Raphael("map", 600, 500); 
 
        //调用绘制地图方法 
        paintMap(R); 
 
        var i = 0; 
        for (var state in china) { 
            china[state][&#39;path&#39;].color = Raphael.getColor(0.9); (function(st, state) { 
                var prodata = data[i]; 
                var fillcolor = colors[arr[i]]; 
                st.attr({ 
                    fill: fillcolor 
                }); //填充背景色 
                xOffset = 70; 
                yOffset = 180; 
                st.hover(function(e) { 
                    st.animate({ 
                        fill: "#fdd", 
                        stroke: "#eee" 
                    }, 
                    500); 
                    R.safari(); 
                    $("#tip").css({ 
                        "top": (e.clientY - xOffset) + "px", 
                        "left": (e.clientX - yOffset) + "px" 
                    }).fadeIn("fast").html("<h4 id="nbsp-nbsp-china-state-name-nbsp-nbsp">" + china[state][&#39;name&#39;] + "</h4><p>活跃用户数:" + prodata + "</p>"); 
                }, 
                function() { 
                    st.animate({ 
                        fill: fillcolor, 
                        stroke: "#eee" 
                    }, 
                    500); 
                    R.safari(); 
                    $("#tip").hide(); 
                }); 
 
                st.mousemove(function(e) { 
                    $("#tip").css({ 
                        "top": (e.clientY - xOffset) + "px", 
                        "left": (e.clientX - yOffset) + "px" 
                    }); 
                    R.safari(); 
                }); 
 
            })(china[state][&#39;path&#39;], state); 
            i++; 
        } 
    }); 
}); 
 
function string2Array(string) { 
    eval("var result = " + decodeURI(string)); 
    return result; 
}

For more related PHP knowledge, please visit php tutorial!

The above is the detailed content of PHP+jQuery realizes the statistical display effect of China map hotspot data. For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:cnblogs. If there is any infringement, please contact admin@php.cn delete
What is the best way to send an email using PHP?What is the best way to send an email using PHP?May 08, 2025 am 12:21 AM

ThebestapproachforsendingemailsinPHPisusingthePHPMailerlibraryduetoitsreliability,featurerichness,andeaseofuse.PHPMailersupportsSMTP,providesdetailederrorhandling,allowssendingHTMLandplaintextemails,supportsattachments,andenhancessecurity.Foroptimalu

Best Practices for Dependency Injection in PHPBest Practices for Dependency Injection in PHPMay 08, 2025 am 12:21 AM

The reason for using Dependency Injection (DI) is that it promotes loose coupling, testability, and maintainability of the code. 1) Use constructor to inject dependencies, 2) Avoid using service locators, 3) Use dependency injection containers to manage dependencies, 4) Improve testability through injecting dependencies, 5) Avoid over-injection dependencies, 6) Consider the impact of DI on performance.

PHP performance tuning tips and tricksPHP performance tuning tips and tricksMay 08, 2025 am 12:20 AM

PHPperformancetuningiscrucialbecauseitenhancesspeedandefficiency,whicharevitalforwebapplications.1)CachingwithAPCureducesdatabaseloadandimprovesresponsetimes.2)Optimizingdatabasequeriesbyselectingnecessarycolumnsandusingindexingspeedsupdataretrieval.

PHP Email Security: Best Practices for Sending EmailsPHP Email Security: Best Practices for Sending EmailsMay 08, 2025 am 12:16 AM

ThebestpracticesforsendingemailssecurelyinPHPinclude:1)UsingsecureconfigurationswithSMTPandSTARTTLSencryption,2)Validatingandsanitizinginputstopreventinjectionattacks,3)EncryptingsensitivedatawithinemailsusingOpenSSL,4)Properlyhandlingemailheaderstoa

How do you optimize PHP applications for performance?How do you optimize PHP applications for performance?May 08, 2025 am 12:08 AM

TooptimizePHPapplicationsforperformance,usecaching,databaseoptimization,opcodecaching,andserverconfiguration.1)ImplementcachingwithAPCutoreducedatafetchtimes.2)Optimizedatabasesbyindexing,balancingreadandwriteoperations.3)EnableOPcachetoavoidrecompil

What is dependency injection in PHP?What is dependency injection in PHP?May 07, 2025 pm 03:09 PM

DependencyinjectioninPHPisadesignpatternthatenhancesflexibility,testability,andmaintainabilitybyprovidingexternaldependenciestoclasses.Itallowsforloosecoupling,easiertestingthroughmocking,andmodulardesign,butrequirescarefulstructuringtoavoidover-inje

Best PHP Performance Optimization TechniquesBest PHP Performance Optimization TechniquesMay 07, 2025 pm 03:05 PM

PHP performance optimization can be achieved through the following steps: 1) use require_once or include_once on the top of the script to reduce the number of file loads; 2) use preprocessing statements and batch processing to reduce the number of database queries; 3) configure OPcache for opcode cache; 4) enable and configure PHP-FPM optimization process management; 5) use CDN to distribute static resources; 6) use Xdebug or Blackfire for code performance analysis; 7) select efficient data structures such as arrays; 8) write modular code for optimization execution.

PHP Performance Optimization: Using Opcode CachingPHP Performance Optimization: Using Opcode CachingMay 07, 2025 pm 02:49 PM

OpcodecachingsignificantlyimprovesPHPperformancebycachingcompiledcode,reducingserverloadandresponsetimes.1)ItstorescompiledPHPcodeinmemory,bypassingparsingandcompiling.2)UseOPcachebysettingparametersinphp.ini,likememoryconsumptionandscriptlimits.3)Ad

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool