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 = {
//提示框,鼠标悬浮交互时的信息提示。
tooltip: {
trigger: 'item',
formatter: "{a} <br/>{b}: {c} ({d}%)"
},
//图例
legend: {
selectedMode: false, //取消图例上的点击事件
orient: 'horizontal', //布局 纵向布局 图例标记居文字的左边 vertical则反之
width: 100, //图例组件的宽度,默认自适应
x: '50%', //图例显示在右边
y: 'center', //图例在垂直方向上面显示居中
data: ['直接访问', '邮件营销', '联盟广告', '视频广告', '搜索引擎'],
textStyle: { //图例文字的样式
color: '#333', //文字颜色
fontSize: 12 //文字大小
},
itemWidth: 12,
itemHeight: 12
},
//色值 (按顺序选取)
color: ['#62d1de', '#54d6b6', '#a6db69', '#ffd454', '#ffa361', '#d1d1d1'],
series: [
{
name: '访问来源', //系统名称
type: 'pie', //类型
center: ['25%', '50%'], //圆心坐标,不设置默认在中心位置
radius: ['50%', '70%'], //饼图半径
avoidLabelOverlap: false,
label: {
normal: {
show: false,
position: 'center'
},
emphasis: {
show: true,
textStyle: {
fontSize: '16',
fontWeight: 'bold'
}
}
},
labelLine: {
normal: {
show: false
}
},
data: [
{value: 335, name: '直接访问'},
{value: 310, name: '邮件营销'},
{value: 234, name: '联盟广告'},
{value: 135, name: '视频广告'},
{value: 1548, name: '搜索引擎'}
]
/*
(function () {
var arr1 = [];
wx.request({
url: "https://www.baifubao.com/callback?cmd=1059&callback=phone&phone=13854322342",
method: 'post',
dataType: 'json',
success: res => {
console.log(2323);
arr1 = [
{ value: 335, name: '直接访问' },
{ value: 310, name: '邮件营销' }
]
},
fail: function (a) {
console.log(a)
arr1 = [
{ value: 335, name: '直接访问' },
{ value: 310, name: '邮件营销' }
]
}
})
console.log(arr1)
return arr1
})()
*/
}
]
};
chart.setOption(option);
return chart;
}
// pages/bill/history.js
Page({
/**
* 页面的初始数据
*/
data: {
datetabs: [],
ec: {
onInit: initChart
},
selectedIdx: 0
},
在page{}外边的函数,怎么拿到函数里的data值来修改?
早解决了,回来答一下,使用懒加载lazyload那个例子就可以,之前用错文档的例子了