1.先来个效果图
这里我用的是插件@antv/f2-canvas(安装的方法如下)
npm init 此处如果直接使用官方npm install 可能会出现没有node_modules错误
npm install --production 建议使用–production选项,可以减少安装一些业务无关的 npm 包,从而减少整个小程序包的大小
npm i @antv/f2-canvas 安装微信小程序 F2 图表组件
安装好依赖包之后,运行 (点击开发者工具顶部详情,勾选 使用npm模块,再点击菜单栏中工具下的构建npm即可运行)
json文件里加这个
"usingComponents": {
"ff-canvas": "@antv/f2-canvas"
}
js文件
const F2 = require('@antv/wx-f2');
let chart = null;
page({
data:{
opts: {
lazyLoad: true
},
},
// 折线图
getMothElectro: function (type) {
let that = this;
// 体重曲线表
app.post('/user/Charts', {
type: type
}).then((res) => {
// console.log(res)
that.setData({
list: res.data.list
})
//这里是把后台返的数据做一下处理
let arr = [];
let array1 = [];
let array2 = [];
let weightArr = [];
// for (let value of res.chart) {
for (let i = 0; i < res.chart.length; i++) {
let value = res.chart[