1. 程式人生 > >Asp.net+Vue2構建簡單記賬WebApp之六(vue.js構建記賬統計頁面)

Asp.net+Vue2構建簡單記賬WebApp之六(vue.js構建記賬統計頁面)

import { Toast } from 'mint-ui'; // 按需引入echart模板 let echarts = require('echarts/lib/echarts'); require('echarts/lib/chart/pie'); require('echarts/lib/chart/line'); require('echarts/lib/component/tooltip'); require('echarts/lib/component/title'); export default{ data(){ return{ LineData:[],//曲線圖資料
PieData:[],// 餅圖資料 date:new Date(), // 時間 } }, methods:{ // 獲取曲線圖資料 GetChartLineData(){ this.$http.post('/bill/GetCount', { Date: this.date, Type:0, GroupBy:1, User: '1' }).then(response => { if(response.body.result.result) { this
.LineData = response.body.result.data; }else { Toast(response.body.result.data) } }, response => { Toast("獲取資料出錯"); }); }, // 獲取餅圖資料 GetPieData(){ this.$http.post('/bill/GetCount', { Date:this.date, Type:0
, User: '1', }).then(response => { if(response.body.result.result) { this.PieData = response.body.result.data; }else { Toast(response.body.result.data) } }, response => { Toast("獲取資料出錯"); }); }, // 繪製圖表 DrawPieChart(){ // 基於準備好的dom,初始化echarts例項 let myChart = echarts.init(document.getElementById('ChartPie')); let data = this.PieData; // 繪製圖表 myChart.setOption({ tooltip: { trigger: 'item', formatter: "{a} <br/>{b} : {c} ({d}%)" }, series: [ { name: '消費', type: 'pie', radius: '55%', center: ['50%', '50%'], data: data } ] }); }, DrawLineChart(){ // 基於準備好的dom,初始化echarts例項 let myChart = echarts.init(document.getElementById('ChartLine')); let data = this.LineData; let x=[],y=[],count=0; for(let i of data) { x.push(i.name); y.push(i.value); count+=i.value; } // 繪製圖表 myChart.setOption({ title : { text: count, subtext: '單位(元)', x:'right' }, tooltip: { trigger: 'axis' }, calculable: false, grid: { x: 12, y: 10, x2: 12, y2: 30, borderWidth: 0 }, xAxis: [ { splitLine: { show: false }, type: 'category', boundaryGap: false, data: x } ], yAxis: [ { show: false, type: 'value' } ], series: [ { name: '消費', type: 'line', center: ['10%', '10%'], smooth: true, itemStyle: { normal: { areaStyle: { type: 'default' } } }, data: y }, ] }); } }, // 監測變化 watch:{ PieData:function () { this.DrawPieChart(); // 繪製表格 }, LineData:function () { this.DrawLineChart(); // 繪製表格 } }, // 建立後執行 mounted(){ this.GetChartLineData(); this.GetPieData(); } }