echart在微信小程序的使用簡單示例
更新時間:2023年02月21日 09:43:13 作者:程序猿向前跑
最近公司的項目中需要在小程序內(nèi)使用echarts組件來展示數(shù)據(jù),下面這篇文章主要給大家介紹了關(guān)于echart在微信小程序的使用方法,文中通過實例代碼介紹的非常詳細(xì),需要的朋友可以參考下
echarts不顯示在微信小程序
<!-- 微信小程序的echart的使用 --> <view class="container"> <ec-canvas id="mychart-dom-bar" canvas-id="mychart-bar" ec="{{ ec }}"></ec-canvas> </view>
css樣式
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; }
echarts的grid屬性詳解
- grid配置項:圖標(biāo)離容器的距離
- show:是否顯示直角坐標(biāo)系網(wǎng)格-----------值:true?false
- left:圖表離容器左側(cè)的距離-----------------值:number?百分比
- top:圖表離容器頂部的距離-----------------值:number?百分比
- right:圖表離容器右側(cè)的距離---------------值:number?百分比
- bottom:圖表離容器底部的距離------------值:number?百分比
- backgroundColor:網(wǎng)格背景色-------------值:rgba或#000000
- borderColor:網(wǎng)格的邊框顏色--------------值:rgba或#000000
- borderWidth:網(wǎng)格的邊框線寬-------------值:number
- 備注:背景色-邊框-線寬生效前提:設(shè)置了show:true,邊距不受show影響
js
import * as echarts from '../../base-ui/ec-canvas/echarts'; let chart = null; function initChart(canvas, width, height, dpr) { chart = echarts.init(canvas, null, { width: width, height: height, devicePixelRatio: dpr // new }); canvas.setChart(chart); var option = { tooltip: { trigger: 'axis', axisPointer: { type: 'shadow' } }, xAxis: { type: 'category', data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'], axisLabel:{ fontSize:10 }, }, yAxis: { type: 'value', }, series: [ { data: [-120, 200, 150, 80, -70, 110, 130], type: 'bar' } ] }; 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() { setTimeout(function () { // 獲取 chart 實例的方式 // console.log(chart) }, 2000); } });
總結(jié)
到此這篇關(guān)于echart在微信小程序的使用的文章就介紹到這了,更多相關(guān)echart在微信小程序的使用內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
javascript對象的property和prototype是這樣一種關(guān)系
javascript對象的property和prototype是這樣一種關(guān)系...2007-03-03給before和after偽元素設(shè)置js效果的方法
本文通過實例給大家介紹給before和after偽元素設(shè)置js效果的方法,對js偽元素相關(guān)知識感興趣的朋友一起學(xué)習(xí)吧2015-12-12JavaScript 使用Ckeditor+Ckfinder文件上傳案例詳解
這篇文章主要介紹了JavaScript 使用Ckeditor+Ckfinder文件上傳案例詳解,本篇文章通過簡要的案例,講解了該項技術(shù)的了解與使用,以下就是詳細(xì)內(nèi)容,需要的朋友可以參考下2021-08-08javascript+ajax實現(xiàn)產(chǎn)品頁面加載信息
本文給大家分享的是使用javascript結(jié)合ajax實現(xiàn)產(chǎn)品頁面無刷新加載信息的代碼,非常的簡單實用,有需要的小伙伴可以參考下。2015-07-07