From 4c2fe71409c7318b85119bf63be0e311ba2f73f3 Mon Sep 17 00:00:00 2001 From: terrywan Date: Thu, 11 Aug 2022 11:58:37 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=E4=BC=A0=E9=80=92thi?= =?UTF-8?q?s=E4=BB=A5=E6=8F=90=E4=BE=9B=E8=87=AA=E5=AE=9A=E4=B9=89?= =?UTF-8?q?=E7=BB=84=E4=BB=B6=E5=86=85=E5=8F=AF=E4=BB=A5=E6=B8=B2=E6=9F=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 文档参考: https://developers.weixin.qq.com/miniprogram/dev/api/canvas/wx.createCanvasContext.html CanvasContext wx.createCanvasContext(string canvasId, Object this) 在自定义组件下,当前组件实例的this,表示在这个自定义组件下查找拥有 canvas-id 的 canvas ,如果省略则不在任何自定义组件内查找 --- src/app.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/app.js b/src/app.js index fe3ee55..eb0dd55 100644 --- a/src/app.js +++ b/src/app.js @@ -5,7 +5,7 @@ import Event from './util/event'; import { findCurrentIndex, findRadarChartCurrentIndex, findPieChartCurrentIndex, getSeriesDataItem, getToolTipData } from './components/charts-data' import { calValidDistance } from './components/charts-util'; -let Charts = function(opts) { +let Charts = function(opts, self) { opts.title = opts.title || {}; opts.subtitle = opts.subtitle || {}; opts.yAxis = opts.yAxis || {}; @@ -20,7 +20,7 @@ let Charts = function(opts) { this.opts = opts; this.config = config; - this.context = wx.createCanvasContext(opts.canvasId); + this.context = self ? wx.createCanvasContext(opts.canvasId, self) : wx.createCanvasContext(opts.canvasId); // store calcuated chart data // such as chart point coordinate this.chartData = {}; @@ -121,4 +121,4 @@ Charts.prototype.scrollEnd = function (e) { } } -export default Charts; \ No newline at end of file +export default Charts;