|
@@ -1,77 +1,19 @@
|
|
|
const app = getApp()
|
|
|
import * as echarts from '../../../commpents/ec-canvas/echarts'
|
|
|
-function setOption(chart, piedata) {
|
|
|
- var option = {
|
|
|
- backgroundColor: "#ffffff",
|
|
|
- series: [{
|
|
|
- label: {
|
|
|
- normal: {
|
|
|
- fontSize: 14
|
|
|
- }
|
|
|
- },
|
|
|
- type: 'pie',
|
|
|
- center: ['50%', '50%'],
|
|
|
- radius: ['20%', '40%'],
|
|
|
- data: piedata
|
|
|
- }]
|
|
|
- };
|
|
|
- chart.setOption(option);
|
|
|
- return chart;
|
|
|
-}
|
|
|
-
|
|
|
Page({
|
|
|
data: {
|
|
|
frameStyle: { useTop: true, name: '收入统计', leftArrow: true, useBar: false },
|
|
|
- ec: {
|
|
|
- //onInit: initChart
|
|
|
- // 将 lazyLoad 设为 true 后,需要手动初始化图表
|
|
|
- lazyLoad: true
|
|
|
- }
|
|
|
- },
|
|
|
- initpie: function (piedata) {
|
|
|
- console.log(piedata);
|
|
|
- let ecComponent = this.selectComponent('#mychart-dom-pie');
|
|
|
- ecComponent.init((canvas, width, height, dpr) => {
|
|
|
- // 获取组件的 canvas、width、height 后的回调函数
|
|
|
- // 在这里初始化图表
|
|
|
- const chart = echarts.init(canvas, null, {
|
|
|
- width: width,
|
|
|
- height: height,
|
|
|
- devicePixelRatio: dpr // new
|
|
|
- });
|
|
|
- //调用设定EChart报表状态的函数,并且把从后端拿到的数据传过去
|
|
|
- setOption(chart, piedata);
|
|
|
- // 注意这里一定要返回 chart 实例,否则会影响事件处理等
|
|
|
- return chart;
|
|
|
- })
|
|
|
+
|
|
|
},
|
|
|
// 返回
|
|
|
back(e) {
|
|
|
wx.navigateBack({ delta: 1 })
|
|
|
},
|
|
|
+
|
|
|
/**
|
|
|
* 生命周期函数--监听页面加载
|
|
|
*/
|
|
|
onLoad: function (options) {
|
|
|
- const that = this;
|
|
|
- var piedata = [{
|
|
|
- value: 55,
|
|
|
- name: '北京'
|
|
|
- }, {
|
|
|
- value: 20,
|
|
|
- name: '武汉'
|
|
|
- }, {
|
|
|
- value: 10,
|
|
|
- name: '杭州'
|
|
|
- }, {
|
|
|
- value: 20,
|
|
|
- name: '广州'
|
|
|
- }, {
|
|
|
- value: 38,
|
|
|
- name: '上海'
|
|
|
- }];
|
|
|
- that.initpie(piedata);
|
|
|
-
|
|
|
},
|
|
|
// 监听用户是否登录
|
|
|
watchLogin: async function () {
|
|
@@ -79,17 +21,75 @@ Page({
|
|
|
wx.getStorage({
|
|
|
key: 'user',
|
|
|
success: async res => {
|
|
|
-
|
|
|
+ that.setData({ ec: { onInit: that.initChart } })
|
|
|
+ that.data.date = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '12', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23', '24', '25', '26', '27', '28', '29', '30', '31'];
|
|
|
+ that.data.money = [900, 270, 340, 400, 600, 700, 310, 300, 270, 340, 344, 300, 320, 310, 300, 270, 340, 344, 300, 500, 310, 300, 270, 340, 344, 300, 320, 310, 300, 270, 340, 344, 300, 320, 310];
|
|
|
},
|
|
|
fail: async res => {
|
|
|
- // wx.redirectTo({ url: '/pages/index/index' })
|
|
|
+ wx.redirectTo({ url: '/pages/index/index' })
|
|
|
}
|
|
|
})
|
|
|
},
|
|
|
+ // 柱状图
|
|
|
+ initChart(canvas, width, height, dpr) {
|
|
|
+ let that = this;
|
|
|
+ var date = that.data.date;
|
|
|
+ var money = that.data.money;
|
|
|
+ const chart = echarts.init(canvas, null, {
|
|
|
+ width: width,
|
|
|
+ height: height,
|
|
|
+ devicePixelRatio: dpr // new
|
|
|
+ });
|
|
|
+ canvas.setChart(chart);
|
|
|
+ var option = {
|
|
|
+ tooltip: {
|
|
|
+ trigger: 'axis',
|
|
|
+ axisPointer: { type: 'shadow' },
|
|
|
+ confine: true
|
|
|
+ },
|
|
|
+ legend: { data: [] },
|
|
|
+ grid: {
|
|
|
+ left: 20,
|
|
|
+ // right: 20,
|
|
|
+ bottom: 15,
|
|
|
+ // top: 40,
|
|
|
+ containLabel: true
|
|
|
+ },
|
|
|
+ xAxis: [
|
|
|
+ {
|
|
|
+ type: 'value',
|
|
|
+ name: '金额',
|
|
|
+ axisLine: { lineStyle: { color: '#999' } },
|
|
|
+ axisLabel: { color: '#666' }
|
|
|
+ }
|
|
|
+ ],
|
|
|
+ yAxis: [
|
|
|
+ {
|
|
|
+ type: 'category',
|
|
|
+ name: '日期',
|
|
|
+ axisTick: { show: false },
|
|
|
+ data: date,
|
|
|
+ axisLine: { lineStyle: { color: '#999' } },
|
|
|
+ axisLabel: { color: '#666' }
|
|
|
+ }
|
|
|
+ ],
|
|
|
+ series: [
|
|
|
+ {
|
|
|
+ name: '收入',
|
|
|
+ type: 'bar',
|
|
|
+ label: { normal: { show: true, position: 'inside' } },
|
|
|
+ data: money,
|
|
|
+ itemStyle: {}
|
|
|
+ },
|
|
|
+ ],
|
|
|
|
|
|
+ };
|
|
|
+ chart.setOption(option, true);
|
|
|
+ return chart;
|
|
|
+ },
|
|
|
/**
|
|
|
- * 生命周期函数--监听页面初次渲染完成
|
|
|
- */
|
|
|
+ * 生命周期函数--监听页面初次渲染完成
|
|
|
+ */
|
|
|
onReady: function () { },
|
|
|
/**
|
|
|
* 生命周期函数--监听页面显示
|
|
@@ -130,4 +130,4 @@ Page({
|
|
|
onShareAppMessage: function (res) {
|
|
|
|
|
|
},
|
|
|
-})
|
|
|
+})
|