<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                ### 圖表Echart使用 ***** 1、克隆:`git clone https://gitee.com/hhhero/echarts-for-weixin.git` 2、復制`ec-canvas`文件夾到小程序中,一般放pages同級目錄中,看項目目錄設計吧 ![](https://img.kancloud.cn/c4/a9/c4a9e40f5626b03b06d1db16ef6b64d3_302x262.png) 3、這時候你看到的并沒有`echarts.min.js`,而是全量的`echarts.js`,這時候可以[定制Echarts](https://echarts.apache.org/zh/builder.html)你所需要的圖表,然后在 其它選項中選擇代碼壓縮 下載即可得到`echarts.min.js`。 ![](https://img.kancloud.cn/8e/11/8e1194f7ff7a71525fe8400bee176499_1514x744.png) 4、修改`ec-canvas.js`導入文件名稱 `import *as echarts from './echarts.min';` ![](https://img.kancloud.cn/a4/46/a4460969ef56fdc9ae1e747b883ecbb4_1073x399.png) 5、小程序page中使用 ``` // .json文件 "usingComponents":?{ ????"ec-canvas":?"../../ec-canvas/ec-canvas" ??} ``` ``` // .wxml文件 <ec-canvas??style="height:?500rpx;width: 100%;"?id="mychart-first" ??canvas-id="mychart-first"?ec="{{?ecEchart?}}"></ec-canvas> ``` ``` // .js文件 let options = { barOption: { // 配置項 // ... } } // 存放繪制對象 let myChart = { chartOne: null } function?init({canvas, width, height, dpr, optionKey})?{ ??let?chart?=?echarts.init(canvas,?null,?{ ????width:?width, ????height:?height, ????devicePixelRatio:?dpr?//?像素 ??}); ??chart.showLoading();?//?首次顯示加載動畫 ??canvas.setChart(chart); ??let?option?=?options[optionKey] ??chart.setOption(option); ??chart.hideLoading();?//?隱藏加載動畫 ??return?chart; } function?initOneChart(canvas,?width,?height,?dpr)?{ ??myChart.chartOne?=?init({canvas,width,height,dpr,optionKey:?'barOption'}); ??return?myChart.chartOne; } Page({ data:{ ecEchart:?{ ??????onInit:?initOneChart ????} }, onReady() { this.getEcharts() }, getEcharts() { let?setOne?=?{ ????????xAxis:?{ ??????????data:?[]?//異步請求返回數據,如 ['2021-08-01','2021-08-02',...] ????????}, ????????series:?[{ ??????????name:?'收入分析', ??????????data:?[]?// 異步請求返回數據,如 [12,33,...] ????????}] ????} myChart.chartOne.setOption(setOne); } }) ``` 收工,如下圖所示: ![](https://img.kancloud.cn/42/d3/42d311f9aae2ceb9c6f660681372a775_457x401.png) ### 問題 ***** * 問題一:頁面滾動,圖表像是添加了`position: fixed;`一樣,不跟隨父級滾動。 引發原因:在掛在圖表元素的某個父級,存在以下樣式,導致 ``` height:100vh; overflow-y:auto; overflow-x:hidden; ``` ![](https://img.kancloud.cn/07/9b/079b961d2cc3cc936c41101137bbcfc2_460x402.png) 解決:把樣式`height:100vh;`去除。 * 問題二:手機橫屏,圖表做不到重新繪制,導致模糊等情況,如下圖,圖二x軸坐標上顯示有些變扭曲。 :-: 圖一: ![](https://img.kancloud.cn/6f/b2/6fb2e3eeee35891d736db5d0d2965ddd_615x454.png) :-: 圖二: ![](https://img.kancloud.cn/86/b5/86b5e6e96e27147bf2c4b12cfeea10b2_524x215.png) 解決: 第一步:.json文件添加 `"pageOrientation":"auto",` 允許橫屏; 第二步:.js文件添加 `onResize(res){}`,監聽手機橫屏變化,以便做相應處理; 第三步:經過上面兩步,以為直接 `chart.resize()`就可以了嗎?小程序并不這么友好啊!!!坑出現了。 還需要配合以下幾步:重新繪制需要 `wx.nextTick(() => {}) // 視圖更新完成,使得chart不等undefined` 、 視圖`wx:if` 和 `chart.setOption(options)`; 說明:視圖通過`wx:if`控制組件,配合`setOption(options)`才能實現(橫屏)重新繪制,除此之外也沒有發現其他方法了。 ![](https://img.kancloud.cn/5a/fd/5afde1132164aedb3576341122d6362d_1510x707.png) :-: 豎屏效果: ![](https://img.kancloud.cn/9f/bd/9fbdd9a977d00d490a75ab4fe1f3c1f6_493x330.png) :-: 橫屏效果: ![](https://img.kancloud.cn/e3/1e/e31e2e512630dbbaafe78f4307ef54cc_1555x729.png) ### 其他信息 ***** [GitHub](https://github.com/wwmingly/ec-echart-wx): https://github.com/wwmingly/ec-echart-wx
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看