Table of Contents
"+china[state]['name']+"
Home php教程 php手册 php和jquery实现地图区域数据统计展示数据示例

php和jquery实现地图区域数据统计展示数据示例

Jun 06, 2016 pm 08:25 PM
Statistics

我们要在地图上有限的区块内展示更多的信息,更好的办法是通过地图交互来实现。本文将给大家讲解通过鼠标滑动到地图指定省份区域,在弹出的提示框中显示对应省份


php和jquery实现地图区域数据统计展示数据示例

HTML

首先在head部分载入raphael.js库文件和chinamapPath.js路径信息文件,本文不重复写下,唯一不同的地方是需要在body中加一个div#tip,用来展示地图信息的提示框。

复制代码 代码如下:




jQuery

通过调用raphael绘制出中国地图,然后载入统计数据,由于地图区块小,我们不在地图载入的时候就将数据显示在地图区块上了,,我们通过鼠标交互实现将数据信息更好的展示给用户。当鼠标滑向省份区块时,通过e.pageX和e.pageY定位鼠标坐标,然后通过jquery的css()方法定位提示框div#tip,并且将对应省份的的名称和活跃用户数加到提示框里并展现出来,请看代码:

复制代码 代码如下:


$(function(){
    $.get("json.php",function(json){

    ......//这里省略代码若干

    var i=0;
    for (var state in china) {
        china[state]['path'].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.pageY-xOffset)+"px","left":(e.pageX-yOffset)+"px"}).fadeIn("fast")
                .html("

"+china[state]['name']+"

活跃用户数:"+prodata+"

");
            },function(){//鼠标离开
                st.animate({fill: fillcolor, stroke: "#eee"}, 500);
                R.safari();
                $("#tip").hide();
            });

            st.mousemove(function(e){//鼠标移动
                $("#tip").css({"top":(e.pageY-xOffset)+"px","left":(e.pageX-yOffset)+"px"});
                R.safari();
            });

         })(china[state]['path'], state);
         i++;
    }
    });
});

以上代码可以看出,通过jQuery的hover()鼠标滑向省份区块时,调用弹出提示框,并将数据载入显示在提示框中,而值得关注的是,我们还需要加一个效果,就是鼠标在省份区块上移动mousemove()的时候,也应该调用提示框跟随鼠标一起移动,否则的话当鼠标在一个省份区块内滑动的话提示框位置不会变化,这样会影响体验效果,小小的改动可以提升用户体验。
最后,如果您需要定制提示框的效果的话,可以设置提示框的CSS样式,本例简单的CSS代码如下:

复制代码 代码如下:


#tip{position:absolute; width:180px; border:1px solid #d3d3d3; background:#fff;display:none;
-moz-border-radius:5px; -webkit-border-radius:5px; overflow:hidden; border-radius:5px;
-moz-box-shadow:1px 1px 2px rgba(0,0,0,.2); -webkit-box-shadow:1px 1px 2px rgba(0,0,0,.2); 
box-shadow:1px 1px 2px rgba(0,0,0,.2);}
#tip h4{height:28px; line-height:28px; padding-left:6px; background:#f0f0f0}
#tip p{line-height:24px; padding:2px 4px}

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

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

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1664
14
PHP Tutorial
1268
29
C# Tutorial
1246
24
Use MySQL to create statistical tables to implement data analysis functions Use MySQL to create statistical tables to implement data analysis functions Jul 01, 2023 pm 05:36 PM

Use MySQL to create statistical tables to implement data analysis functions. In the era of big data, data analysis has become an important basis for decision-making. As a commonly used relational database, MySQL can also implement data analysis functions by creating data statistics tables. This article will introduce how to use the features of MySQL to create statistical tables and demonstrate its use through code examples. First, we need to define the structure of the data statistics table. Generally speaking, a data statistics table contains two parts: dimensions and measures. Dimensions are attributes that describe data, such as time

PHP Kuaishou API interface tutorial: How to implement user data analysis and statistics PHP Kuaishou API interface tutorial: How to implement user data analysis and statistics Jul 21, 2023 pm 04:53 PM

PHP Kuaishou API Interface Tutorial: How to implement user data analysis and statistics. With the rise of social media, Kuaishou has become one of the popular platforms for many people to share and watch short videos. As a developer, we can use Kuaishou's API interface to analyze and collect user data. This tutorial will introduce how to use the PHP programming language to achieve user data acquisition, analysis and statistics through the Kuaishou API interface. Step 1: Obtain the API interface key. First, we need to apply for an API interface key on the Kuaishou open platform. Applying

Data statistics and user behavior analysis in PHP real-time chat system Data statistics and user behavior analysis in PHP real-time chat system Aug 13, 2023 am 10:16 AM

Overview of data statistics and user behavior analysis in PHP real-time chat system: With the development of the Internet and the popularity of smartphones, real-time chat systems have become an indispensable part of people's daily lives. Whether on social media platforms or in internal corporate communications, live chat systems play an important role. This article will discuss data statistics and user behavior analysis in the PHP real-time chat system, and provide relevant code examples. Statistics: Statistics in the real-time chat system can help us understand user activity

Quick Start: Use Go language functions to implement simple data statistics functions Quick Start: Use Go language functions to implement simple data statistics functions Jul 31, 2023 pm 03:45 PM

Quick Start: Use Go language functions to implement simple data statistics functions Introduction: Go language, as a simple, efficient and reliable programming language, is widely used in the field of software development. Among them, functions, as one of the core features of the Go language, provide programmers with powerful tools to solve problems. This article will introduce how to use Go language functions to implement simple data statistics functions, helping readers better understand and apply Go language functions. 1. Requirements analysis Before starting to write code, we first need to analyze our needs clearly, that is

How to use Vue to implement statistical charts of map data How to use Vue to implement statistical charts of map data Aug 18, 2023 pm 04:46 PM

How to use Vue to implement statistical charts of map data. With the increasing demand for data analysis, data visualization has become a powerful tool. The statistical charts of map data can visually display the data distribution and help users better understand and analyze the data. This article will introduce how to use the Vue framework to implement statistical charts of map data, and attach code examples. First, we need to introduce Vue.js and related plug-ins, such as Vue-echarts and Echarts. Vue-echarts is Vue.

How to use Laravel to implement data statistics and analysis functions How to use Laravel to implement data statistics and analysis functions Nov 04, 2023 pm 12:09 PM

How to use Laravel to implement data statistics and analysis functions Laravel is a popular PHP framework that provides a wealth of functions and tools to facilitate developers to build efficient web applications. Among them, data statistics and analysis are an integral part of many applications. This article will introduce how to use the Laravel framework to implement data statistics and analysis functions, and provide some specific code examples. 1. Install and configure Laravel First, we need to install and configure the Laravel framework. OK

Learn user behavior analysis and data statistics in JavaScript Learn user behavior analysis and data statistics in JavaScript Nov 03, 2023 am 09:39 AM

Learning user behavior analysis and data statistics in JavaScript requires specific code examples. With the development of Internet technology, user experience and data statistics have become more and more important for the development of websites and applications. User behavior analysis and data statistics can help developers understand user behavior patterns on websites or applications, and then optimize product design and functionality. JavaScript is a commonly used programming language in user behavior analysis and data statistics. It can be done by inserting some JavaScr into the web page

How to use arrays for data statistics in PHP How to use arrays for data statistics in PHP Jul 09, 2023 pm 11:54 PM

How to use arrays for data statistics in PHP In PHP, arrays are a very useful data structure that can be used to store and operate multiple data items. By using arrays, we can easily perform statistics and analysis on data. This article will introduce how to use arrays for data statistics and provide some sample code to illustrate. Count Statistics One of the most common data statistics operations is count statistics. We can use an array to store a set of data, and then use the array's counting function to count the number of times each element appears in the array. Below is an example

See all articles