(备注:以下例子小程序加入了vant组件)
第一步首先引入echarts
下载echarts微信版 地址: https://github.com/ecomfe/echarts-for-weixin
(定制版的echarts体积更小,而且小程序中用到的图表种类不会很多,自己定制,然后替换掉他的echarts.js)
Json引入:
{
"usingComponents": {
"van-tabs": "/miniprogram_npm/@vant/weapp/tabs/index",
"van-tab": "/miniprogram_npm/@vant/weapp/tab/index",
"ec-canvas": "../../ec-canvas/ec-canvas",【引入echarts组件】
"van-popup":"/miniprogram_npm/@vant/weapp/popup/index",
"van-picker":"/miniprogram_npm/@vant/weapp/picker/index",
"van-picker-column":"/miniprogram_npm/@vant/weapp/picker-column/index",
"van-field":"/miniprogram_npm/@vant/weapp/field/index"
},
"navigationBarTitleText": "采购情况"
}
js:
// pages/demoEcharts/demoEcharts.js
// 引入echarts
import * as echarts from '../../ec-canvas/echarts';
// 获取应用实例
const app = getApp();
//建立一个全局变量(注意,放在page外面,要全局变量,可以动态修改)
var monthList = [];
var avePriceList1 = [];
var avePriceList2 = [];
var myChartTwo = null;
Page({
/**
* 页面的初始数据
*/
data: {
active: 0,
ecTwo: {
lazyLoad: true //在data中设置延迟加载
},