小程序使用echarts-條形統(tǒng)計(jì)圖

timg.jpg

先看效果圖

image.png

下載 GitHub 上的 ecomfe/echarts-for-weixin 項(xiàng)目

1.首先在app.json中新建一個(gè)頁面("pages/echarts/echarts")


image.png

2.將下載好的echarts-for-weixin-master進(jìn)行解壓后找到ec-canvas該文件夾,將該文件夾粘貼到項(xiàng)目中


image.png

3.在echarts.json中進(jìn)行配置
{
  "usingComponents": {
    "ec-canvas":"../../ec-canvas/ec-canvas"
  },
  "navigationBarTitleText": "統(tǒng)計(jì)圖"
}

4.echarts.wxml

<view class="content-echarts">
    <ec-canvas id="mychart-line" canvas-id="mychart-line" ec="{{ec}}"></ec-canvas>
  </view>

5.echarts.js

// pages/echarts/echarts.js
import * as echarts from '../../ec-canvas/echarts'
function initChart(canvas,width,height){
  const chart = echarts.init(canvas,null,{
    width:width,
    height:height
  })
  canvas.setChart(chart)
  var option = {
    color: ['#FFCC00'],
    title: {
      text: '本周銷量統(tǒng)計(jì)圖'
    },
    tooltip: {},
    legend: {
      data: ['銷量']
    },
    xAxis: {
      data: ["周一", "周二", "周三", "周四", "周五", "周六",'周日']
    },
    yAxis: {},
    series: [{
      name: '銷量',
      type: 'bar',
      data: [5, 20, 36, 10, 13, 20,38]
    }]
  };
  chart.setOption(option)
  return chart
}
Page({
  /**
   * 頁面的初始數(shù)據(jù)
   */
  data: {
   ec:{onInit:initChart}
  },
  /**
   * 用戶點(diǎn)擊右上角分享
   */
  onShareAppMessage: function () {
    return {
      title: '在微信中使用echarts',
      path: 'pages/echarts/echarts',
      success: function (res) { },
      fail: function () { }
    }
  }
})

6.echarts.wxss

/* pages/echarts/echarts.wxss */
.content-echarts{
  position: absolute;
  top: 25%;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
}
ec-canvas{
  width:100%;
  height: 600rpx;
  background: #fff;
}
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

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

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