收藏
回答

使用canvas报undefined is not an Object?(部分机型报错)?

async onReady() {
			await this.getConclusion()
			uni.createSelectorQuery().select('#myCanvas').fields({
				node: true,
				size: true,
			}).exec((res) => {
				if (res && res[0]) {
					const system = uni.getSystemInfoSync()
					const w = system.windowWidth / 750
					const canvas = res[0].node
					const ctx = canvas.getContext('2d') // 渲染上下文
					// Canvas 画布的实际绘制宽高
					const width = res[0].width
					const height = res[0].height
					// 初始化画布大小
					const dpr = uni.getWindowInfo().pixelRatio
					canvas.width = width * dpr
					canvas.height = height * dpr
					ctx.scale(dpr, dpr)
					ctx.clearRect(0, 0, width, height)
					// 绘制个人标准差曲线图
					// this.drawSelfStandardDeviation(ctx, w)
					// 绘制个人常模标准差曲线图
					console.log('是我这里错了吗')
					this.drawNormData(ctx, w, width)
				}
			})
			uni.createSelectorQuery().select('#myCanvas2').fields({
				node: true,
				size: true,
			}).exec((res) =>{
				if (res && res[0]) {
					const system = uni.getSystemInfoSync()
					const w = system.windowWidth / 750
					const canvas = res[0].node
					const ctx = canvas.getContext('2d') // 渲染上下文
					// Canvas 画布的实际绘制宽高
					const width = res[0].width
					const height = res[0].height
					// 初始化画布大小
					const dpr = uni.getWindowInfo().pixelRatio
					canvas.width = width * dpr
					canvas.height = height * dpr
					ctx.scale(dpr, dpr)
					ctx.clearRect(0, 0, width, height)
					this.drawPieChart(ctx, w, width, height)
				}
			})
		},

这里测试的时候有一部ios的手机有这个问题,大部分机型没问题,想不明白这个有什么解决办法。

回答关注问题邀请回答
收藏

2 个回答

  • 社区技术运营专员--许涛
    社区技术运营专员--许涛
    2022-11-01

    你好,麻烦提供出现问题的具体机型、微信版本号、系统版本号,以及能复现问题的代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html)

    2022-11-01
    有用
    回复
  • 一笑皆春
    一笑皆春
    2022-10-31

    提供个复现的代码片段吧

    2022-10-31
    有用
    回复 2
    • 21
      21
      2022-10-31
      这个看看行不
      2022-10-31
      回复
    • 21
      21
      2022-10-31
      2022-10-31
      回复
登录 后发表内容