uniapp使用echarts

uniapp使用echarts

1.下载资源包

https://echarts.apache.org/zh/download.html

2.引入资源包

将资源包放入项目内

3.代码示例

javascript 复制代码
<template>
	<div style="width:100%;height:500rpx" id="line" ref="line"></div>
</template>

<script>
	import * as echarts from '@/config/echarts.min.js';
	export default {
		data() {
			return {
				chartDom: "",
				myChart: "",
				option: "",
			};
		},
		// onLoad() {
		// 	this.$nextTick(() => {
		// 		this.chartDom = document.getElementById("main");
		// 		this.myChart = echarts.init(this.chartDom);
		// 		this.initChart();
		// 	});
		// },
		mounted() {
			this.$nextTick(() => {
				this.initChart();
			});
		},
		methods: {
			initChart() {
				this.chartDom = document.getElementById("line");
				this.myChart = echarts.init(this.chartDom);
				// return;
				// this.chart = echarts.init(this.$el, "macarons");

				this.option = {
					tooltip: {
						trigger: 'axis',
						axisPointer: {
							type: 'shadow'
						}
					},
					legend: {},
					grid: {
						left: '3%',
						right: '4%',
						bottom: '3%',
						containLabel: true
					},
					xAxis: [{
						type: 'category',
						data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
					}],
					yAxis: [{
						type: 'value'
					}],
					series: [{
							name: 'Direct',
							type: 'bar',
							emphasis: {
								focus: 'series'
							},
							data: [320, 332, 301, 334, 390, 330, 320]
						},
						{
							name: 'Email',
							type: 'bar',
							stack: 'Ad',
							emphasis: {
								focus: 'series'
							},
							data: [120, 132, 101, 134, 90, 230, 210]
						},
						{
							name: 'Union Ads',
							type: 'bar',
							stack: 'Ad',
							emphasis: {
								focus: 'series'
							},
							data: [220, 182, 191, 234, 290, 330, 310]
						},
						{
							name: 'Video Ads',
							type: 'bar',
							stack: 'Ad',
							emphasis: {
								focus: 'series'
							},
							data: [150, 232, 201, 154, 190, 330, 410]
						},
						{
							name: 'Search Engine',
							type: 'bar',
							data: [862, 1018, 964, 1026, 1679, 1600, 1570],
							emphasis: {
								focus: 'series'
							},
							markLine: {
								lineStyle: {
									type: 'dashed'
								},
								data: [
									[{
										type: 'min'
									}, {
										type: 'max'
									}]
								]
							}
						},
						{
							name: 'Baidu',
							type: 'bar',
							barWidth: 5,
							stack: 'Search Engine',
							emphasis: {
								focus: 'series'
							},
							data: [620, 732, 701, 734, 1090, 1130, 1120]
						},
						// {
						// 	name: 'Google',
						// 	type: 'bar',
						// 	stack: 'Search Engine',
						// 	emphasis: {
						// 		focus: 'series'
						// 	},
						// 	data: [120, 132, 101, 134, 290, 230, 220]
						// },
						// {
						// 	name: 'Bing',
						// 	type: 'bar',
						// 	stack: 'Search Engine',
						// 	emphasis: {
						// 		focus: 'series'
						// 	},
						// 	data: [60, 72, 71, 74, 190, 130, 110]
						// },
						// {
						// 	name: 'Others',
						// 	type: 'bar',
						// 	stack: 'Search Engine',
						// 	emphasis: {
						// 		focus: 'series'
						// 	},
						// 	data: [62, 82, 91, 84, 109, 110, 120]
						// }
					]
				};
				this.option && this.myChart.setOption(this.option);
			},
		},
	}
</script>

<style>
</style>

注意事项

div中的id 需要对应document中的id,且最好是唯一的,不重复的

相关推荐
Vicky&James1 分钟前
WPF到Web的无缝过渡:英雄联盟客户端项目OpenSilver迁移实战
前端·wpf
m0_748233645 分钟前
RabbitMQ 进阶
android·前端·后端
不想有bug的小菜鸟14 分钟前
vue3使用iframe全屏展示pdf效果
前端·pdf
m0_7482386314 分钟前
Spring Boot项目接收前端参数的11种方式
前端·spring boot·后端
u01005596015 分钟前
前端代理,解决跨域问题讲解
前端
quitv20 分钟前
react脚手架配置别名
前端·javascript·react.js
m0_5287238129 分钟前
前端如何进行性能优化
前端·性能优化
化作繁星30 分钟前
在 Vue 3 中,如何缓存和复用动态组件
前端·vue.js·缓存
一粒沙-1 小时前
iOS 将GIF图分享至微信
前端·ios
graywen1 小时前
从文本到图像:SSE 如何助力 AI 内容实时呈现?(Typescript篇)
前端