微信小程序Echarts圖表組件使用方法詳解
1:下載 GitHub 上的 項(xiàng)目
2:但項(xiàng)目下載之后,打開(kāi)小程序開(kāi)發(fā)工具,可以看到效果如下,適配性還是比較完美的。
如果是在項(xiàng)目里面引入組件的話,打開(kāi)從github上面下載的代碼,將ec-canvas文件夾復(fù)制黏貼到你的項(xiàng)目里面。
好的,組件已經(jīng)復(fù)制到了我的項(xiàng)目里面,現(xiàn)在我想實(shí)現(xiàn)一個(gè)折線圖,現(xiàn)在開(kāi)始去組件里面搬運(yùn)復(fù)制黏貼代碼了。
wxml
<!--index.wxml--> <view class="container"> <ec-canvas id="mychart-dom-line" canvas-id="mychart-line" ec="{{ ec }}"></ec-canvas> </view>
js
import * as echarts from '../../ec-canvas/echarts'; const app = getApp(); function initChart(canvas, width, height) { const chart = echarts.init(canvas, null, { width: width, height: height }); canvas.setChart(chart); var option = { title: { text: '測(cè)試下面legend的紅色區(qū)域不應(yīng)被裁剪', left: 'center' }, color: ["#37A2DA", "#67E0E3", "#9FE6B8"], legend: { data: ['A', 'B', 'C'], top: 50, left: 'center', backgroundColor: 'red', z: 100 }, grid: { containLabel: true }, tooltip: { show: true, trigger: 'axis' }, xAxis: { type: 'category', boundaryGap: false, data: ['周一', '周二', '周三', '周四', '周五', '周六', '周日'], // show: false }, yAxis: { x: 'center', type: 'value', splitLine: { lineStyle: { type: 'dashed' } } // show: false }, series: [{ name: 'A', type: 'line', smooth: true, data: [18, 36, 65, 30, 78, 40, 33] }, { name: 'B', type: 'line', smooth: true, data: [12, 50, 51, 35, 70, 30, 20] }, { name: 'C', type: 'line', smooth: true, data: [10, 30, 31, 50, 40, 20, 10] }] }; chart.setOption(option); return chart; } Page({ onShareAppMessage: function (res) { return { title: 'ECharts 可以在微信小程序中使用啦!', path: '/pages/index/index', success: function () { }, fail: function () { } } }, data: { ec: { onInit: initChart } }, onReady() { } });
json
{ "usingComponents": { "ec-canvas": "../../ec-canvas/ec-canvas" } }
css
/**index.wxss**/ ec-canvas { width: 100%; height: 100%; }
這一步為止,代碼搬運(yùn)結(jié)束,刷新按鈕,但是,為什么界面顯示空白?沒(méi)有報(bào)錯(cuò),代碼也一模一樣,真實(shí)讓人費(fèi)解,算了,還是先放在這里吧,吃飯要緊。
.......
.......
繼續(xù)寫(xiě)
對(duì),沒(méi)錯(cuò),空白不顯示的原因出在了css文件上面,只要我們?cè)赾ss里面再寫(xiě)上一些代碼之后。
/**index.wxss**/ ec-canvas { width: 100%; height: 100%; } ec-canvas { width: 100%; height: 100%; } .container { position: absolute; top: 0; bottom: 0; left: 0; right: 0; display: flex; flex-direction: column; align-items: center; justify-content: space-between; box-sizing: border-box; } .picker-pos { margin-top: -130rpx; margin-left: 150rpx; color: blueviolet; }
這個(gè)時(shí)候
小程序Echarts圖表組件算是已經(jīng)可以運(yùn)用在項(xiàng)目里面啦
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- 微信小程序中使用echarts的實(shí)現(xiàn)方法
- 微信小程序使用echarts獲取數(shù)據(jù)并生成折線圖
- uniapp在微信小程序中使用ECharts的方法
- 微信小程序中使用ECharts 異步加載數(shù)據(jù)的方法
- 微信小程序Echarts覆蓋正常組件問(wèn)題解決
- uni-app微信小程序使用echarts的詳細(xì)圖文教程
- 微信小程序在ios下Echarts圖表不能滑動(dòng)的問(wèn)題解決
- 微信小程序遍歷Echarts圖表實(shí)現(xiàn)多個(gè)餅圖
- 微信小程序使用ECharts的示例詳解
- 微信小程序中使用echarts方法(全網(wǎng)最詳細(xì)教程!)
相關(guān)文章
TypeScript基礎(chǔ)入門(mén)教程之三重斜線指令詳解
這篇文章主要給大家介紹了關(guān)于TypeScript基礎(chǔ)入門(mén)教程之三重斜線指令的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2018-10-10Openlayers實(shí)現(xiàn)距離面積測(cè)量
這篇文章主要為大家詳細(xì)介紹了Openlayers實(shí)現(xiàn)距離面積測(cè)量,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-09-09完美解決js傳遞參數(shù)中加號(hào)和&號(hào)自動(dòng)改變的方法
下面小編就為大家?guī)?lái)一篇完美解決js傳遞參數(shù)中加號(hào)和&號(hào)自動(dòng)改變的方法。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2016-10-10Object的相關(guān)方法 和 js遍歷對(duì)象的常用方法總結(jié)
這篇文章主要介紹了Object的相關(guān)方法 和 js遍歷對(duì)象的常用方法,結(jié)合實(shí)例形式總結(jié)分析了Object對(duì)象操作的操作方法與js遍歷的三種常用方法,需要的朋友可以參考下2023-05-05javascript實(shí)現(xiàn)TreeView 無(wú)刷新展開(kāi)的實(shí)例代碼
這篇文章介紹了javascript實(shí)現(xiàn)TreeView 無(wú)刷新展開(kāi)的實(shí)例代碼,有需要的朋友可以參考一下2013-07-07JavaScript Canvas繪制動(dòng)態(tài)線框效果
這篇文章主要為大家詳細(xì)介紹了JavaScript Canvas繪制動(dòng)態(tài)線框效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-08-08