echarts label固定位置_Taro/微信小程序实现echarts点击获取动态数据

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

首先我们需要看看需求:

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

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

然后需要注册组件:

config = {
    
    usingComponents: {
    
      'ec-canvas': '../ec-canvas/ec-canvas'
    }
  }

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

<ec-canvas
    ref={this.refHistoryHipperChart}
    canvas-id="mychart-history-hipper"
    ec={ec}
    />
<ec-canvas
    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', () 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值