Detailed explanation of Javascript Echarts air quality map effect

Detailed explanation of Javascript Echarts air quality map effect

We need to first combine the air quality data with the map data:

Map data has the attribute name

insert image description here

Our different cities' air quality also has a name attribute. These two attributes are the same, both called name, so we can associate them:

var airData = [
      { name: 'Beijing', value: 39.92 },
      { name: 'Tianjin', value: 39.13 },
      { name: 'Shanghai', value: 31.22 },
      { name: 'Chongqing', value: 66 },
      { name: 'Hebei', value: 147 },
      { name: 'Henan', value: 113 },
      { name: 'Yunnan', value: 25.04 },
      { name: 'Liaoning', value: 50 },
      { name: 'Heilongjiang', value: 114 },
      { name: 'Hunan', value: 175 },
      { name: 'Anhui', value: 117 },
      { name: 'Shandong', value: 92 },
      { name: 'Xinjiang', value: 84 },
      { name: 'Jiangsu', value: 67 },
      { name: 'Zhejiang', value: 84 },
      { name: 'Jiangxi', value: 96 },
      { name: 'Hubei', value: 273 },
      { name: 'Guangxi', value: 59 },
      { name: 'Gansu', value: 99 },
      { name: 'Shanxi', value: 39 },
      { name: 'Inner Mongolia', value: 58 },
      { name: 'Shaanxi', value: 61 },
      { name: 'Jilin', value: 51 },
      { name: 'Fujian', value: 29 },
      { name: 'Guizhou', value: 71 },
      { name: 'Guangdong', value: 38 },
      { name: 'Qinghai', value: 57 },
      { name: 'Tibet', value: 24 },
      { name: 'Sichuan', value: 58 },
      { name: 'Ningxia', value: 52 },
      { name: 'Hainan', value: 54 },
      { name: 'Taiwan', value: 88 },
      { name: 'Hong Kong', value: 66 },
      { name: 'Macao', value: 77 },
      { name: 'South China Sea Islands', value: 55 }
    ]

Next we need to configure the air quality data into the series:

insert image description here

Finally, do some effect configuration:

insert image description here

insert image description here

Full code:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Map-Air Quality in Different Cities</title>
  <script src="./lib/echarts.js"></script>
  <script src="./lib/axios.js"></script>
</head>
<body>
  <div style="width: 600px; height: 400px;border: 1px solid lightblue;"></div>
  <script>
    var airData = [
      { name: 'Beijing', value: 39.92 },
      { name: 'Tianjin', value: 39.13 },
      { name: 'Shanghai', value: 31.22 },
      { name: 'Chongqing', value: 66 },
      { name: 'Hebei', value: 147 },
      { name: 'Henan', value: 113 },
      { name: 'Yunnan', value: 25.04 },
      { name: 'Liaoning', value: 50 },
      { name: 'Heilongjiang', value: 114 },
      { name: 'Hunan', value: 175 },
      { name: 'Anhui', value: 117 },
      { name: 'Shandong', value: 92 },
      { name: 'Xinjiang', value: 84 },
      { name: 'Jiangsu', value: 67 },
      { name: 'Zhejiang', value: 84 },
      { name: 'Jiangxi', value: 96 },
      { name: 'Hubei', value: 273 },
      { name: 'Guangxi', value: 59 },
      { name: 'Gansu', value: 99 },
      { name: 'Shanxi', value: 39 },
      { name: 'Inner Mongolia', value: 58 },
      { name: 'Shaanxi', value: 61 },
      { name: 'Jilin', value: 51 },
      { name: 'Fujian', value: 29 },
      { name: 'Guizhou', value: 71 },
      { name: 'Guangdong', value: 38 },
      { name: 'Qinghai', value: 57 },
      { name: 'Tibet', value: 24 },
      { name: 'Sichuan', value: 58 },
      { name: 'Ningxia', value: 52 },
      { name: 'Hainan', value: 54 },
      { name: 'Taiwan', value: 88 },
      { name: 'Hong Kong', value: 66 },
      { name: 'Macao', value: 77 },
      { name: 'South China Sea Islands', value: 55 }
    ]
    var myCharts = echarts.init(document.querySelector('div'))
    
    axios.get('./json/map/china.json').then(res => {
      console.log(res.data)
      echarts.registerMap('china', res.data)
      var option = {
        geo: {
          type: 'map',
          map: 'china',
          roam: true,
          label: {
            show: true
          }
        },
        series: [
          {
            data: airData, // air quality data geoIndex: 0, // associate air quality data with the 0th geo configuration type: 'map'
          }
        ],
        visualMap:
          min: 0, // minimum value max: 300, // maximum value inRange: {
            color: ['pink', 'blue'] // Control the lower left corner and map gradient color},
          calculable: true // Control the lower left slider}
      }
      myCharts.setOption(option)
    })
  </script>
</body>
</html>

Summarize

This article ends here. I hope it can be helpful to you. I also hope that you can pay more attention to more content on 123WORDPRESS.COM!

You may also be interested in:
  • JavaScript data visualization: ECharts map making
  • An article to solve the echarts map carousel highlight
  • Python uses pyecharts to visualize map data
  • vue+echarts realizes the flow effect of China map (detailed steps)
  • vue+echarts+datav large screen data display and implementation of China map province, city and county drill-down function
  • Case study of introducing Chinese map in echarts in vue

<<:  21 MySQL standardization and optimization best practices!

>>:  Docker image creation Dockerfile and commit operations

Recommend

Implementation of React virtual list

Table of contents 1. Background 2. What is a virt...

How MLSQL Stack makes stream debugging easier

Preface A classmate is investigating MLSQL Stack&...

Solution to Nginx session loss problem

In the path of using nginx as a reverse proxy tom...

Vue uses element-ui to implement menu navigation

This article shares the specific code of Vue usin...

HTML hyperlink style (four different states) setting example

Copy code The code is as follows: <style type=...

What are the benefits of using B+ tree as index structure in MySQL?

Preface In MySQL, both Innodb and MyIsam use B+ t...

Explanation and example usage of 4 custom instructions in Vue

Four practical vue custom instructions 1. v-drag ...

Introduction to Linux File Compression and Packaging

1. Introduction to compression and packaging Comm...

HTML table tag tutorial (44): table header tag

<br />In order to clearly distinguish the ta...

MySQL merge and split by specified characters example tutorial

Preface Merging or splitting by specified charact...

Problems encountered when updating the auto-increment primary key id in Mysql

Table of contents Why update the auto-increment i...

Introduction to Nginx log management

Nginx log description Through access logs, you ca...