小程序的圖表(例子是柱狀圖)---wxCharts

1.下載wxcharts.js

2.小程序js頁面引入,例如:var wxCharts = require('../../utils/wxcharts.js');? (路徑要寫對)


3.HTML

<canvas canvas-id="columnCanvas" disable-scroll="true" class="pieCanvas" ></canvas>

4.CSS

.pieCanvas{

? width:690rpx;

? height:452rpx;

? margin: 0 auto;

}

5.JS(因為圖標(biāo)默認(rèn)展示是高清圖,而且寬高不隨著頁面尺寸變化,所以需要自定義寬度)


var winWidth = wx.getSystemInfoSync().windowWidth;//獲取窗口的寬度

? ? this.setData({

? ? ? width:winWidth

? ? })

動態(tài)設(shè)置數(shù)據(jù)




參數(shù)說明

//獲取條形圖數(shù)據(jù)

? getCusList: function (){

? ? var that = this;

? ? var categories = [];

? ? var valList = [];

? ? util.getRequestPromise(config.service.getCusStaData,'').then(data => {

? ? ? let result = data ? data : [];

? ? ? if (result.length > 0){

? ? ? ? result.forEach(function (item, i, arr) {

? ? ? ? ? categories.push(item.stateName);

? ? ? ? ? valList.push(item.count);

? ? ? ? });

? ? ? ? that.setData({

? ? ? ? ? categories: categories,

? ? ? ? ? valList: valList

? ? ? ? });

? ? ? ? that.echars(categories, valList);

? ? ? }

? ? });

? },



echars(categories, valList){

? ? new wxCharts({

? ? ? canvasId: 'columnCanvas',

? ? ? type: 'column',

? ? ? animation: true,

? ? ? categories: categories,

? ? ? series: [{

? ? ? ? data: valList,

? ? ? ? color: '#2A76FF',

? ? ? ? name: '狀態(tài)分布(人)'

? ? ? }],

? ? ? yAxis: {

? ? ? ? disabled: true,

? ? ? ? min: 0,

? ? ? ? max:10,

? ? ? },

? ? ? animation: true,

? ? ? xAxis: {

? ? ? ? type: 'calibration',

? ? ? ? disableGrid: false,

? ? ? },

? ? ? extra: {

? ? ? ? column: {

? ? ? ? ? width: 15

? ? ? ? }

? ? ? },

? ? ? width: this.data.width-30,

? ? ? height: 190,

? ? ? legend: true,

? ? });

? },

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容