博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
小程序使用echarts封装成自定义组件的实现方法
阅读量:4094 次
发布时间:2019-05-25

本文共 1422 字,大约阅读时间需要 4 分钟。

小程序中自定义 echarts 组件,实现复用的方法。

1下载echarts

2 json 中引入echarts 组件

"usingComponents": {        "ec-canvas": "../ec-canvas/ec-canvas"    }

3 js 中引入echarts 组件及方法

import * as echarts from '../ec-canvas/echarts'Component({    /**     * 组件的属性列表     */    properties: {        chartLineId: { type: String },        canvasId: { type: String },        height: { type: String },        options: { type: Object }    },    /**     * 组件的初始数据     */    data: {        ec: {            lazyLoad: true, // 延迟加载        },    },    lifetimes: {        ready() {            this[this.data.chartLineId] = this.selectComponent('#' + this.data.chartLineId);            this.getData();        },        detached(e) {            this[this.data.chartLineId] = null            this[this.data.canvasId] = null        },    },    /**     * 组件的方法列表     */    methods: {        getData() {            this.initChart();        },        initChart() {            this[this.data.chartLineId].init((canvas, width, height, dpr) => {                const chart = echarts.init(canvas, null, {                    width: width,                    height: height,                    devicePixelRatio: dpr // new                })                chart.setOption(this.getOption())                return chart            })        },        getOption() {            var option = this.data.options;            return option;        },    }})

4 wxml

子组件

父组件

转载地址:http://dovii.baihongyu.com/

你可能感兴趣的文章
Jenkins+Gradle+Gitlab+蒲公英 +打包成功后发送邮件配置
查看>>
Vue router 页面刷新 参数
查看>>
数据库实践课程实验(mysql)
查看>>
linux网络编程之用socket实现简单客户端和服务端的通信(基于TCP)
查看>>
Linux下网络socket编程——实现服务器(select)与多个客户端通信
查看>>
IO多路复用之epoll总结
查看>>
inet_pton, inet_ntop
查看>>
htonl(), ntohl(), htons(), ntohs() 函数
查看>>
inet_ntoa、 inet_aton、inet_addr
查看>>
用模板写单链表
查看>>
用模板写单链表
查看>>
链表各类操作详解
查看>>
C++实现 简单 单链表
查看>>
数据结构之单链表——C++模板类实现
查看>>
Linux的SOCKET编程 简单演示
查看>>
正则匹配函数
查看>>
Linux并发服务器编程之多线程并发服务器
查看>>
常量指针与指针常量的区别(转帖)
查看>>
聊聊gcc参数中的-I, -L和-l
查看>>
[C++基础]034_C++模板编程里的主版本模板类、全特化、偏特化(C++ Type Traits)
查看>>