小程序引入Echarts

1.下载 GitHub 上的 ecomfe/echarts-for-weixin 项目
2.echarts下载,在线定制,选择图表,代码压缩

3.替换项目ec-canvas中的echarts.js

4.page.json引入

{
  "usingComponents": {
    "ec-canvas":"../../../../ec-canvas/ec-canvas"
  }
}
5.js中引入
import * as echarts from "../../../../ec-canvas/echarts"
 
//初始化
init(arr){
      this.lazyComponent.init((canvas,width,height,dpr)=>{
        let chart=echarts.init(canvas,null,{
          width:width,height:height,devicePixelRation:dpr
        })
        let option=this.getOption(arr)
        chart.setOption(option)
        this.chart=chart
        return chart
      })  
},
 
 getOption(arr){
      return{

xAxis: {
type: 'category',
data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
},
yAxis: {
type: 'value'
},
series: [
{
data: arr,
type: 'bar'
}
]

}
}
 
//调用
 this.lazyComponent=this.selectComponent("#myChart-dom")
 this.init([120, 200, 150, 80, 70, 110, 130])
posted @ 2021-12-04 21:53  码渣渣123  阅读(133)  评论(0)    收藏  举报