uniapp-echarts

本文档详细介绍了如何在uni-app中集成ECharts,包括安装、在线定制ECharts JS文件,解决初始化报错问题,以及如何创建并使用自定义主题。在集成过程中,针对'this.echarts.setCanvasCreator is not a function'和't.addEventListener is not a function'的错误,提供了具体的代码修复方案。最后,阐述了如何通过ECharts主题编辑器创建自定义主题,并在uni-app中应用。
摘要由CSDN通过智能技术生成

目录

开始使用

遇到问题

使用自定义主题


开始使用

1. 引入 npm install echarts mpvue-echarts

2. ECharts 在线构建 定制 echarts 的 js 文件

3. 新建 common 文件夹,将定制文件放在 common 下

4. 将 node_modules 下 mpvue-echarts 中除 src 文件夹之外的部分删除,mpvue-echarts文件夹复制到 components 文件夹下,删除node_modules

5.创建components/my-echart/my-echart.vue文件 

<template>
	<view class="echarts-wrap">
		<myechart ref="mapChart" :echarts="echarts" :onInit="initChart" />

	</view>
</template>

<script>
	import * as echarts from '@/common/echarts.min.js';
	import myechart from '@/components/mpvue-echarts/src/echarts.vue';
	import theme from '@/common/chalk.js';
	var that=''
	export default {
		name: '',
		props: [],
		components: {
			myechart
		},
		data() {
			return {
				echarts
			}
		},
		onReady() {
			uni.hideHomeButton()
		},
		computed: {},
		watch: {},
		methods: {
			initChart(canvas, width, height) {
				// console.log('图标', canvas);
				let chart = null
				echarts.registerTheme('theme', theme)
				chart = echarts.init(canvas, 'theme', {
					width: width,
					height: height
				});
				var option = {
					animationDuration: 500,
					throttleTouch: true,
					title: {
						text: ''
					},
					// toolbox: {
					//     feature: {
					//       dataZoom: {
					//         yAxisIndex: 'none'
					//       },
					//       restore: {},
					//       saveAsImage: {}
					//     }
					//   },
					dataZoom: [{
						show: true,
						type: 'slider',
						startValue: 0,
						endValue: 5
					}],
					legend: {
						show: false
					},
					grid: {
						top: '4%',
						left: '3%',
						right: '4%',
						bottom: '20%',
						containLabel: true
					},
					xAxis: {
						data: ['1
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值