diff --git a/src/common/components/chart/index.tsx b/src/common/components/chart/index.tsx index f64f462..4e7d09f 100644 --- a/src/common/components/chart/index.tsx +++ b/src/common/components/chart/index.tsx @@ -64,21 +64,23 @@ const LineChart: React.FC = (props) => { }, []); const drawLineChart = () => { const query = Taro.createSelectorQuery(); - query - .select(`#${id ?? DEFAULT_CHART_ID}`) - .fields({ node: true, size: true }) - .exec((res) => { - const dpr = Taro.getSystemInfoSync().pixelRatio; - const canvas = res[0].node as CanvasInterface; - const { width, height } = canvas; - canvas.width = width * dpr; - canvas.height = height * dpr; - // 设置 canvas 组件的样式宽高 - setSize({ x: width ?? 200, y: height ?? 200 }); - const ctx = canvas.getContext('2d') as CanvasContext; - ctx.scale(dpr, dpr); - drawChart(ctx); - }); + setTimeout(() => { + query + .select(`#${id ?? DEFAULT_CHART_ID}`) + .fields({ node: true, size: true }) + .exec((res) => { + const dpr = Taro.getSystemInfoSync().pixelRatio; + const canvas = res[0].node as CanvasInterface; + const { width, height } = canvas; + canvas.width = width * dpr; + canvas.height = height * dpr; + // 设置 canvas 组件的样式宽高 + setSize({ x: width ?? 200, y: height ?? 200 }); + const ctx = canvas.getContext('2d') as CanvasContext; + ctx.scale(dpr, dpr); + drawChart(ctx); + }); + }, 200); }; const drawChart = (ctx: CanvasContext) => { @@ -178,14 +180,15 @@ const LineChart: React.FC = (props) => { return ( ))} - +