From 65a273c0253ee7d59c962d6e7a35dda0e476786a Mon Sep 17 00:00:00 2001 From: Fay Date: Thu, 22 Aug 2019 14:54:51 +0800 Subject: [PATCH] =?UTF-8?q?CHART-10293=20=E6=8D=A2=E6=88=90canvas=E6=B5=8B?= =?UTF-8?q?=E5=AE=BD=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/core/platform/web/dom.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/core/platform/web/dom.js b/src/core/platform/web/dom.js index 022c996dae..55db4615a2 100644 --- a/src/core/platform/web/dom.js +++ b/src/core/platform/web/dom.js @@ -125,14 +125,16 @@ var canvas = document.createElement("canvas"); var ratio = 2; BI.Widget._renderEngine.createElement("body").append(canvas); - var w = BI.DOM.getTextSizeWidth(param, 12) + 4; + + var ctx = canvas.getContext("2d"); + ctx.font = "12px Georgia"; + var w = ctx.measureText(param).width + 4; canvas.width = w * ratio; canvas.height = 16 * ratio; - var ctx = canvas.getContext("2d"); - // ctx.fillStyle = "#EAF2FD"; ctx.font = 12 * ratio + "px Georgia"; ctx.fillStyle = fillStyle || "#3685f2"; ctx.textBaseline = "middle"; + // ctx.fillStyle = "#EAF2FD"; ctx.fillText(param, 2 * ratio, 9 * ratio); BI.Widget._renderEngine.createElement(canvas).destroy(); var backColor = backgroundColor || "rgba(54, 133, 242, 0.1)";