taro更新页面数据_Taro/微信小程序实现echarts点击获取动态数据

本文介绍了如何在Taro小程序中使用Echarts实现数据统计功能。通过Echarts的点击事件,结合柱形图和扇形图,展示了选择日期后展示对应月份的数据,并在点击柱形图时更新扇形图的详细信息。文章详细讲解了Echarts的引入、组件注册、图表初始化、事件监听及数据请求过程。
摘要由CSDN通过智能技术生成

最近在用Taro写一个小程序,有一些数据统计,需要使用到echarts,今天就来说说它的使用方法。

首先我们需要看看需求:

我们需要选择日期,确定显示的月份,然后会展示对应月份的柱形图,当我们点击对应月份时,下面的扇形图会展示对应的详情,所以我们会用到 echarts的点击事件。

首先我们需要下载echarts,然后引入它: import * as echarts from '../ec-canvas/echarts'

然后需要注册组件:

config = {

usingComponents: {

'ec-canvas': '../ec-canvas/ec-canvas'

}

}

然后我们在需要画图的地方定义好需要的图:

ref={this.refHistoryHipperChart}

canvas-id="mychart-history-hipper"

ec={ec}

/>

ref={this.refHistoryRollChart}

canvas-id="mychart-history-roll"

ec={ec}

/>

这分别对应柱形图,和扇形图。ref分别时我们需要获取对应节点的函数:

refHistoryHipperChart = (node) => (this.HistoryHipperChart = node)

refHistoryRollChart = (node) => (this.HistoryRollChart = node)分别存到实例中,方便使用,然后就是渲染函数:

refreshHistoryHipperChart(names, data) {

let _this = this,

clickTime

this.HistoryHipperChart.init((canvas, width, height) => {

const chart = echarts.init(canvas, null, {

width: width,

height: height

})

setChartData(chart, data)

chart.getZr().on('click', () => {

_this.requsetHistoryRollData(clic

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值