小程序柱状折线双图

注意要点:

1,通过小程序提供的canvas组件来绘制。需要注意地方是自定义的组件的包含canvas的时候,创建 canvas 绘图上下文需要使用wx.createCanvasContext(canvasId, this),有疑问请查看微信小程序api介绍https://developers.weixin.qq.com/miniprogram/dev/api/canvas/create-canvas-context.html
2,使用canvasContext.setLineDash虚线完成之后,可以通过以下方式让之后的线条变回实线。

canvasContext.setLineDash([10,0],0)

3,使用canvasContext.createLinearGradient渐变之后,可以通过以下方式让之后的画笔回归正常效果

  let bgrd = context.createLinearGradient(0, 0, 1, 1);
  bgrd.addColorStop(0, items.point.bColor)
  bgrd.addColorStop(1, items.point.bColor)
  context.setFillStyle(bgrd);

4,监听滑动查看效果的时候不用频率太快,只需要每次滑动大小大于x轴间距的一般就行,不然会出现渲染缓慢。

if (Math.abs(e.touches[0].x - this.config.touchDetail.x) > this.config.xAxis.padd / 2) {
    this.config.touchDetail.isShow = true;
    this.config.touchDetail.x = e.touches[0].x;
    this.config.touchDetail.y = e.touches[0].y;
    drawCharts.call(this, this.config.type, this.opts, this.config, this.context);
}
效果图:

折线柱状双图
git地址:https://github.com/fuxingkai/frankui-weapp

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 8
    评论
评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值