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 863e38ff15ff322ebec29acb0cf87e77e1683136..7e337a6e5fc588fcc4504d7b5bb6c9217d3c4b6f 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() {