echarts 实现各种图表

该博客介绍了如何利用echarts库实现中国地图、饼图和柱状图的绘制,涵盖了从基本设置到数据绑定的详细步骤。
摘要由CSDN通过智能技术生成

地图(china map)

// html
<div ref="fillcontainer">
	<div id="fundPosition"></div>
</div>

//js
<script>
import echarts from 'echarts'; // 引入echarts插件
import '../../../node_modules/echarts/map/js/china.js'; // 引入china map数据
import '../../../node_modules/echarts/theme/roma.js' // 引入主题颜色

export default {
   
	data () {
   
		return {
   
			chart: null
		}
	},
	mounted () {
   
		this.$nextTick(function() {
   
			this.$refs.fillcontainer.style.height = (document.body.clientHeight - 160) + 'px';
			this.drawMap('fundPosition') // 传入id
			var that = this;
			var resizeTimer = null;
			// 保证页面在放大或缩小时,也能动态显示数据
			window.onresize = function () {
   
				if (resizeTimer) clearTimeout(resizeTimer);
				resizeTimer = setTimeout(function () {
   
					that.$refs.fillcontainer.style.height = (document.body.clientHeight 160) + 'px';
					that.drawMap('fundPosition');
				}, 100)
			}
		})
	},
	methods: {
   
		randomData () {
   
			return Math.round(Math.random() * 1000000);
		}
		drawMap(id) {
   
			if (this.chart && this.chart.dispose) {
   
				this.chart.dispose(); // 释放图表
			}
			this.chart = echarts.init(document.getElementById(id), "roma") // 第一个参数是ID名,第二个参数是主题色
			this.chart.setOption({
    // 配置图表
				title: {
   
					text: '2021年全国各省份投资情况',
					subtext: '单位/万元',
					left: 'center'
				},
				tooltip: {
   
					trigger: 'item'
				},
				legend: {
   
					orient: 'vertical',
					left: 'left',
					data: ['总投资额']
				},
				visualMap: {
   
					min: 0,
					max: 1200000,
					left: 'left',
					top: 'bottom',
					text: ['高', '低'], // 文本 默认为数值
					calculable: true
				},
				toolbox: {
   
					show: true,
					orient: 'vertical',
					left: 'right',
					top: 'center',
					feature: {
    // 功能按钮
						dataView: {
   readOnly: false}, // 数据视图
						restore: {
   }, // 还原
						saveAsImage: {
   } // 保存为图片
					}
				},
				series: [
					{
   
						name: '总投资额',
						type: 'map',
						mapType: 'china',
						roam: false,
						label: {
   
							normal:{
   
								show: true
							},
							emphasis: {
   
								show: true
							},
							data:[
                            {
   name: '北京',value: this.randomData() },
                            {
   name: '天津',value: this.randomData() },
                            {
   name: '上海',value: this.randomData() },
                            {
   name: '重庆',value: this.randomData() },
                            {
   name: '河北',value: this.randomData() },
                            {
   name: '河南',value: this.randomData() },
                            {
   name: '云南',value: this.randomData() },
                            {
   name: '辽宁',value: this.randomData() },
                            {
   name: '黑龙江',value: this.randomData() },
                            {
   name: '湖南',value: this.randomData() },
                            {
   name: 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值