uniapp使用echarts

1.下载资源包

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

2.引入资源包

将资源包放入项目内
在这里插入图片描述

3.代码示例

<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,且最好是唯一的,不重复的

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
要在uni-app使用ECharts,你可以按照以下步骤进行操作: 1. 安装依赖:你可以通过运行命令`npm install echarts mpvue-echarts --save`来安装ECharts和mpvue-echarts插件。 2. 下载ECharts库文件:从ECharts官方网站下载echarts.min.js文件,并将其放置在uni-app项目的static文件夹中。 3. 创建公共组件:在uni-app项目的components文件夹中新建一个名为echarts.vue的公共组件。 4. 在需要使用ECharts的页面引入ECharts组件:在需要使用ECharts的页面中,通过`import`命令引入之前创建的公共组件echarts.vue。 5. 在页面中使用ECharts组件:在页面的template中使用echarts组件,并根据ECharts使用文档配置相关的图表选项和数据。 这样,你就可以在uni-app使用ECharts来展示图表了。需要注意的是,确保你的依赖安装正确,并且将echarts.min.js文件放置在正确的位置,以确保图表可以正常展示。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [uniapp-Echarts.zip](https://download.csdn.net/download/qq_28584685/12660082)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* *3* [uniapp 使用 echarts实现图表](https://blog.csdn.net/qq_32195805/article/details/125791885)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值