UNI-APP 使用Echart(含地图教程)

1、安装Echart ,加入项目

npm install echarts --save

2、加入地图Map,路径:static/map

------------自行百度寻找资源-----------------

3、初始化组件 ,main.js

import Vue from 'vue'
import App from './App'
import store from './store'
Vue.config.productionTip = false

// 引入vue-echarts组件库
import * as Echarts from 'echarts'
import china from '@/static/map/json/china.json'
Echarts.registerMap('china', china)

Vue.prototype.$echarts = Echarts

App.mpType = 'app'

const app = new Vue({
	store,
    ...App
})
app.$mount()

4、编写组件m-chart ,路径:components/m-chart/m-chart.vue

<template>
	<view>
		<view ref="chart" class="chart"></view>
	</view>
</template>

<script>
	export default {
		name: "m-chart",
		props: {
			options:{
				type: Object,
				default: {}
			}
		},
		data() {
			return {
				chart: ""
			};
		},
		mounted() {
			// 基于准备好的dom,初始化echarts实例
			this.chart = this.$echarts.init(this.$refs.chart.$el);
			// 指定图表的配置项和数据
			this.chart.setOption(this.options);
		},
		watch: {
			options: {
				deep: true,
				handler(val, oVal) {
					this.chart.setOption(this.options);
				}
			}
		}
	}
</script>

<style>
	.chart {
		height: 100%;
		width: 100%;
	}
</style>

5、页面使用

<template>
	<view class="bg">
        <m-chart class="chart2" :options="chartOption"></m-chart>
    </view>
</template>
<script>
	import mChart from '@/components/m-chart/m-chart.vue'
    export default {
		components: {
			mChart
		},
        data(){
            return {
                chartOption:"echart的属性,自行到echart官网查阅"
            }
        }
    }
</script>
<style lang="less" scoped>
	.bg {
		width: 3840rpx;
		height: 2160rpx;
	}
</style>

谢谢观看!

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 5
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值