From 33f5f9329fa1b6c2f69bd43edfa57f5b959dc10f Mon Sep 17 00:00:00 2001 From: LiangXiao Date: Tue, 11 Aug 2020 16:24:31 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E5=8D=87=E7=BA=A7=E3=80=91=20uni-app?= =?UTF-8?q?=20=E5=9C=A8=E5=BE=AE=E4=BF=A1=E7=AB=AF=E4=BD=BF=E7=94=A82.9.0?= =?UTF-8?q?=E8=B5=B7=E6=94=AF=E6=8C=81=E7=9A=84=E4=B8=80=E5=A5=97=E6=96=B0?= =?UTF-8?q?Canvas=202D=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../u-charts.js" | 57 +++++++++++++------ 1 file changed, 39 insertions(+), 18 deletions(-) diff --git "a/uCharts-for-UNIAPP\357\274\210\350\267\250\347\253\257\357\274\211/u-charts.js" "b/uCharts-for-UNIAPP\357\274\210\350\267\250\347\253\257\357\274\211/u-charts.js" index 863e38f..7e337a6 100644 --- "a/uCharts-for-UNIAPP\357\274\210\350\267\250\347\253\257\357\274\211/u-charts.js" +++ "b/uCharts-for-UNIAPP\357\274\210\350\267\250\347\253\257\357\274\211/u-charts.js" @@ -5219,30 +5219,51 @@ var Charts = function Charts(opts) { config$$1.columePadding = config.columePadding * opts.pixelRatio; opts.$this = opts.$this ? opts.$this : this; + // #ifndef MP-WEIXIN this.context = uni.createCanvasContext(opts.canvasId, opts.$this); + // #endif + /* 兼容原生H5 this.context = document.getElementById(opts.canvasId).getContext("2d"); - this.context.setStrokeStyle = function(e){ return this.strokeStyle=e; } - this.context.setLineWidth = function(e){ return this.lineWidth=e; } - this.context.setLineCap = function(e){ return this.lineCap=e; } - this.context.setFontSize = function(e){ return this.font=e+"px sans-serif"; } - this.context.setFillStyle = function(e){ return this.fillStyle=e; } - this.context.draw = function(){ } */ + + // #ifdef MP-WEIXIN + uni.createSelectorQuery().in(opts.$this) + .select(`#${opts.canvasId}`) + .fields({ node: true, size: true }) + .exec((res) => { + const canvas = res[0].node + const ctx = canvas.getContext('2d') + + const dpr = uni.getSystemInfoSync().pixelRatio + canvas.width = res[0].width * dpr + canvas.height = res[0].height * dpr + ctx.scale(dpr, dpr) + + this.context = ctx + this.context.setStrokeStyle = function(e){ return this.strokeStyle=e; } + this.context.setLineWidth = function(e){ return this.lineWidth=e; } + this.context.setLineCap = function(e){ return this.lineCap=e; } + this.context.setFontSize = function(e){ return this.font=e+"px sans-serif"; } + this.context.setFillStyle = function(e){ return this.fillStyle=e; } + this.context.draw = function(){ } + // #endif + opts.chartData = {}; + this.event = new Event(); + this.scrollOption = { + currentOffset: 0, + startTouchX: 0, + distance: 0, + lastMoveTime: 0 + }; - opts.chartData = {}; - this.event = new Event(); - this.scrollOption = { - currentOffset: 0, - startTouchX: 0, - distance: 0, - lastMoveTime: 0 - }; - - this.opts = opts; - this.config = config$$1; + this.opts = opts; + this.config = config$$1; - drawCharts.call(this, opts.type, opts, config$$1, this.context); + drawCharts.call(this, opts.type, opts, config$$1, this.context); + // #ifdef MP-WEIXIN + }) + // #endif }; Charts.prototype.updateData = function() { -- Gitee