How to use ECharts in WeChat Mini Programs using uniapp

How to use ECharts in WeChat Mini Programs using uniapp

Today, we use uniapp to integrate Echarts to display map charts.

Please refer to mpvue-echarts

Reference: https://github.com/F-loat/mpvue-echarts

https://ask.dcloud.net.cn/article/36288

Make improvements

There are many tutorials on the Internet, but they are not very clear. Let's go directly to the steps below.

1. npm install echarts mpvue-echarts

After executing this command, mpvue-echarts and echarts will be generated under node_modules, and then the src under mpvue-echarts will be placed under components, and then the js file of echarts will be customized at https://echarts.apache.org/zh/builder.html, as shown below:

insert image description here

Map implementation:

<template>
	<view class="wrap" >
		<mpvue-echarts id="main" ref="mapChart" :echarts="echarts" @onInit="renderMap" />
	</view>
</template>

<script>
import * as echarts from '@/common/echarts.min'; /*chart.min.js is customized online*/
import * as henanJson from 'echarts/map/json/province/henan.json'; /*chart.min.js is customized online*/
import mpvueEcharts from '@/components/mpvue-echarts/src/echarts.vue';


export default {
	data() {
		return {
			echarts,
		};
	},
	components:
		mpvueEcharts
	},
	onLoad() {
		
	},
	methods: {
		renderMap(e) {
			var mydata = [
				{ name: 'Zhengzhou City', value: 100 },
				{ name: 'Luoyang City', value: 10 },
				{ name: 'Kaifeng City', value: 20 },
				{ name: 'Xinyang City', value: 30 },
				{ name: 'Zhumadian City', value: 40 },
				{ name: 'Nanyang City', value: 41 },
				{ name: 'Zhoukou City', value: 15 },
				{ name: 'Xuchang City', value: 25 },
				{ name: 'Pingdingshan City', value: 35 },
				{ name: 'Xinxiang City', value: 35 },
				{ name: 'Luohe City', value: 35 },
				{ name: 'Shangqiu City', value: 35 },
				{ name: 'Sanmenxia City', value: 35 },
				{ name: 'Jiyuan City', value: 35 },
				{ name: 'Jiaozuo City', value: 35 },
				{ name: 'Anyang City', value: 35 },
				{ name: 'Hebi City', value: 35 },
				{ name: 'Puyang City', value: 35 },
				{ name: 'Kaifeng City', value: 45 }
			];
			let { canvas, width, height } = e;
			echarts.setCanvasCreator(() => canvas);
			const chart = echarts.init(canvas, null, {
				width: width,
				height: height
			});
			echarts.registerMap('henan', henanJson);
			canvas.setChart(chart);
			var optionMap = {
				tooltip: {
					trigger: 'item',
					formatter: '{b}: {c}mg/m³'
				},
				//Small navigation icon on the left visualMap: {
					show:true,
					min: 0,
					max: 100,
					left: 'right',
					orient:'horizontal',
				},
				//Configuration properties series: [
					{
						type: 'map',
						mapType: 'henan',
						label: {
							normal: {
								show: true
							},
							emphasis:
								textStyle: {
									color: '#fff'
								}
							}
						},
						itemStyle: {
							normal: {
								borderColor: '#389BB7',
								areaColor: '#fff'
							},
							emphasis:
								areaColor: '#389BB7',
								borderWidth: 0
							}
						},
						animation: false,
						data: mydata //data }
				]
			};
			//Initialize echarts instance chart.setOption(optionMap);
			this.$refs.mapChart.setChart(chart);
		}
	}
};
</script>

<style scoped lang="scss">
.wrap {
  width: 100%;
  height: 400px;
}
</style>

Effect:

insert image description here

Regarding the json file of the map, in echarts\map

This is the end of this article about how uniapp uses ECharts in WeChat Mini Programs. For more information about how uniapp uses ECharts, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Uniapp WeChat applet: Solution to key failure
  • Uniapp WeChat applet realizes multiple countdowns on one page
  • uniapp, Issues with using MQTT in WeChat applets
  • WeChat applet uniapp realizes the left swipe to delete effect (complete code)

<<:  Tomcat server security settings method

>>:  CentOS server security configuration strategy

Recommend

You may need a large-screen digital scrolling effect like this

The large-screen digital scrolling effect comes f...

Detailed process of NTP server configuration under Linux

Table of contents 1. Environment Configuration 1....

mySQL server connection, disconnection and cmd operation

Use the mysql command to connect to the MySQL ser...

Initial settings after installing Ubuntu 16 in the development environment

The office needs Ubuntu system as the Linux devel...

Detailed explanation of the role and principle of key in Vue

Table of contents 1. Let’s start with the conclus...

How to write object and param to play flash in firefox

Copy code The code is as follows: <object clas...

How to build Git service based on http protocol on VMware+centOS 8

Table of contents 1. Cause 2. Equipment Informati...

How to use vue-video-player to achieve live broadcast

Table of contents 1. Install vue-video-player 2. ...

MySQL: mysql functions

1. Built-in functions 1. Mathematical functions r...

Summary of several APIs or tips in HTML5 that cannot be missed

In previous blog posts, I have been focusing on so...

JavaScript dynamically generates a table with row deletion function

This article example shares the specific code of ...

What are your principles for designing indexes? How to avoid index failure?

Table of contents Primary key index Create indexe...

Let's talk about Vue's mixin and inheritance in detail

Table of contents Preface Mixin Mixin Note (dupli...

HTML table markup tutorial (22): row border color attribute BORDERCOLORLIGHT

Within rows, light border colors can be defined i...