1.准备应用相关组件

echarts--直接 npm install 安装即可

2.home.ts

import { Component,ViewChild,ElementRef } from '@angular/core';
import { IonicPage,NavController,Slides,PopoverController } from 'ionic-angular';
import {SQLiteService} from '../../app/sqlite.service'
import * as echarts from 'echarts'; //引入图表插件 @IonicPage()
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
// @ViewChild(Slides) slides: Slides;
@ViewChild('piecontainer') piecontainer:ElementRef;
monthMoney:number = 0;
dayMoney:number = 0;
yearMoney:number = 0;
optinpielegend : any = [];
strdate:string ='';
strdateMonth:string ='';
stryear:string="";
option = {
title : {
text: '消费类型统计',
x:'center'
},
tooltip : {
trigger: 'item',
formatter: "¥{c}({d}%)"
},
legend: {
x:'center',
y:'bottom',
data: [] },
series : [
{
type: 'pie',
radius : '60%',
center: ['45%', '35%'],
data: [],
itemStyle: {
normal: {
label : {
show : false //隐藏标示文字
},
labelLine : {
show : false //隐藏标示线
}
},
emphasis: {
shadowBlur: 10,
shadowOffsetX: 0,
shadowColor: 'rgba(0, 0, 0, 0.5)'
}
}
}
]
}; constructor(public navCtrl: NavController
,private sqlite: SQLiteService,
public popoverCtrl: PopoverController
) { } getData(){
// return new Promise((resolve,reject)=>{
this.optinpielegend=[];
this.sqlite.database.executeSql("SELECT A.*,sum(ifnull(B.amount,0)) amount FROM consumType A LEFT OUTER JOIN consum B on A.id=B.type group by A.id ",{}).then(res=>{
for(var i=0; i<res.rows.length; i++) {
this.optinpielegend.push({value:res.rows.item(i).amount,name: res.rows.item(i).name});
}
}).catch(e=>{
console.log(e);
});
let datetime=new Date();
let m=datetime.getMonth()<10?"0"+(datetime.getMonth()+1):(datetime.getMonth()+1).toString();
let d=datetime.getDate()<10?"0"+(datetime.getDate()):(datetime.getDate()).toString();
let date=datetime.getFullYear()+"-"+m+"-"+d;
this.strdate=date;
this.strdateMonth=datetime.getFullYear()+"-"+m;
this.stryear=datetime.getFullYear().toString();
this.sqlite.database.executeSql("select ifnull(sum(amount),0) amount from consum where date=? ",[date]).then(
r=>{
this.dayMoney=r.rows.item(0).amount;
}).catch(e=>{
console.log(e);
});
this.sqlite.database.executeSql("select ifnull(sum(amount),0) amount from consum where strftime('%m',date)=? ",[m.toString()]).then(
r=>{
this.monthMoney=r.rows.item(0).amount;
}).catch(e=>{
console.log(e);
});
this.sqlite.database.executeSql("select ifnull(sum(amount),0) amount from consum where strftime('%Y',date)=? ",[datetime.getFullYear().toString()]).then(
r=>{
this.yearMoney=r.rows.item(0).amount;
}).catch(e=>{
console.log(e);
});
//});
} ionViewWillEnter() {
//修复轮播手动滑动后不能自动轮播问题
// this.slides.autoplayDisableOnInteraction = false;
let that=this;
setTimeout(()=>{
that.getData();
},1000);
setTimeout(()=>{
let lengend=[],lengenddata=[];
for (var index = 0; index < this.optinpielegend.length; index++) {
var element = this.optinpielegend[index];
lengend.push(element.name);
lengenddata.push({value:element.value, name:element.name});
}
this.option.legend.data=lengend;
this.option.series[0].data=lengenddata;
echarts.init(that.piecontainer.nativeElement).setOption(this.option,true);
},2000);
}
presentPopover(myEvent) {
let popover = this.popoverCtrl.create('AboutPage');
popover.present({
ev: myEvent
});
}
}

home.module.ts

import { NgModule } from '@angular/core';
import { IonicPageModule } from 'ionic-angular';
import { HomePage } from './home';
import { PipesModule } from '../../pipes/pipes.module';
@NgModule({
declarations: [
HomePage,
],
imports: [
PipesModule,
IonicPageModule.forChild(HomePage),
],
})
export class HomePageModule {}

home.html

<ion-header>
<ion-toolbar>
<ion-buttons start>
<button ion-button icon-only color="royal" (tap)="tapSearch($event)">
<ion-icon name="search"></ion-icon>
</button>
</ion-buttons>
<ion-title>首页</ion-title>
<ion-buttons end>
<button ion-button icon-only color="royal" (click)="presentPopover($event)">
<ion-icon name="more" role="img" class="icon icon-ios ion-ios-more" aria-label="more"></ion-icon>
</button>
</ion-buttons>
</ion-toolbar>
</ion-header>
<ion-content padding>
<!-- <div class="slide-wrap">
<ion-slides pager loop="true" autoplay="3000" >
<ion-slide><img src="assets/imgs/100.png" /></ion-slide>
<ion-slide><img src="assets/imgs/102.png" /></ion-slide>
<ion-slide><img src="assets/imgs/103.png" /></ion-slide>
</ion-slides>
</div> --> <div class="stamp stamp01">
<div class="par"><p>{{strdate}}消费总额</p><sub class="sign">¥</sub><span>{{dayMoney| fmoney:2}}</span></div>
<i></i>
</div> <div class="stamp stamp02">
<div class="par"><p>{{strdateMonth}}消费总额</p><sub class="sign">¥</sub><span>{{monthMoney| fmoney:2}}</span></div>
<i></i>
</div> <div class="stamp stamp03">
<div class="par"><p>{{stryear}}消费总额</p><sub class="sign">¥</sub><span>{{yearMoney | fmoney:2}}</span></div>
<i></i>
</div> <div class="stamp stamp04" *ngFor="let consum of optinpielegend;">
<div class="par"><p>{{consum.name}}</p><sub class="sign">¥</sub><span>{{consum.value | fmoney:2 }}</span></div>
<i></i>
</div>
<div #piecontainer class="echart-pie"></div>
</ion-content>

3.pipes

import { NgModule } from '@angular/core';
import { FmoneyPipe } from './fmoney/fmoney';
@NgModule({
declarations: [FmoneyPipe],
imports: [],
exports: [FmoneyPipe]
})
export class PipesModule {}
import { Pipe, PipeTransform } from '@angular/core';

/**
* Generated class for the FmoneyPipe pipe.
*
* See https://angular.io/api/core/Pipe for more info on Angular Pipes.
*/
@Pipe({
name: 'fmoney',
})
export class FmoneyPipe implements PipeTransform {
/**
* Takes a value and makes it lowercase.
*/
transform(value: string, ...args) {
//return value.toLowerCase();
/*
* 参数说明:
* s:要格式化的数字
* n:保留几位小数
* */
let n = args[0] > 0 && args[0] <= 20 ? args[0] : 2;
value = parseFloat((value + "").replace(/[^\d\.-]/g, "")).toFixed(n) + "";
let l = value.split(".")[0].split("").reverse(),
r = value.split(".")[1];
let t = "";
for (let i = 0; i < l.length; i++) {
t += l[i] + ((i + 1) % 3 == 0 && (i + 1) != l.length ? "," : "");
}
return t.split("").reverse().join("") + "." + r;
}
}

4.修改app.module.ts

import {PipesModule} from '../pipes/pipes.module';
imports:...

PipesModule
...

5.about.ts

import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
import {SQLiteService} from '../../app/sqlite.service'
import { Toast } from '@ionic-native/toast';
/**
* Generated class for the AboutPage page.
*
* See https://ionicframework.com/docs/components/#navigation for more info on
* Ionic pages and navigation.
*/ @IonicPage()
@Component({
selector: 'page-about',
//templateUrl: 'about.html', template:`<ion-list class="list list-md">
<ion-item-divider>
<ion-label class="label label-md">
设置
</ion-label>
<button (click)="cleardata()" ion-button="" item-end="" outline="" class=" item-button button button-md button-outline button-outline-md">
<span class="button-inner">清空数据</span>
<div class="button-effect"></div></button>
</ion-item-divider>
<button ion-item (click)="callphone('1368336534')">
<ion-icon name="call" item-start class="icon-md-secondary" ></ion-icon>
<ion-label class="label label-md" id="lbl-5">1368336534</ion-label>
</button>
<button ion-item (click)="callemial('sulin11026@613.com')">
<ion-icon name="link" item-start class="icon-md-secondary"></ion-icon>
<ion-label class="label label-md" id="lbl-5">sulin11026@613.com</ion-label>
</button>
</ion-list>`
})
export class AboutPage { constructor(public navCtrl: NavController, private sqlite: SQLiteService,
private toast :Toast) {
} ionViewDidLoad() {
console.log('ionViewDidLoad AboutPage');
}
callphone(phone){
window.location.href = "tel:" + phone;
}
callemial(email){
window.location.href="mailto:"+email;
}
cleardata(){
this.sqlite.database.executeSql("delet from consum ",{}).then(res=>{
this.toast.show("清理成功", '5000', 'center').subscribe(
toast => {
console.log(toast);
}
);
}).catch(e=>{
this.toast.show(e, '5000', 'center').subscribe(
toast => {
console.log(toast);
}
);
});
}
}

6.效果展示

代码下载

Ionic3 demo TallyBook 实例3的更多相关文章

  1. Ionic3 demo TallyBook 实例1

    1.创建项目 ionic start  TallyBook  blank  创建一个空的项目 ionic cordova  platform  add android   添加andorid平台 io ...

  2. Ionic3 demo TallyBook 实例2

    1.添加插件 2.相关页面 消费页面: <ion-header> <ion-navbar> <ion-title> 消费记录 </ion-title> ...

  3. appium跑demo简单实例讲解

    安装appium,设置 demo.pyfrom appium import webdriver #要装webdriver,方法查看http://www.cnblogs.com/sincoolvip/p ...

  4. react介绍、环境搭建、demo运行实例

    React官网:https://reactjs.org/docs/create-a-new-react-app.html cnpm网址:http://npm.taobao.org/ 1.react介绍 ...

  5. Ionic3 Demo

    本文为原创文章,转载请标明出处 最近又开源了一个小 Demo,基于 Ionic 3.9.2.注册登录功能使用的是 WildDog 野狗通信云,大家可以放心的注册登录玩.电影相关数据来源自"某 ...

  6. js实现『加载更多』功能实例

    DEMO : 滚动加载示例 关于如何实现『加载更多』功能,网上有插件可用,例如比较著名的使用iscroll.js实现的上拉加载更多.下拉刷新功能. 但实际用起来却是很麻烦.由于是第三方插件,要按照对方 ...

  7. nodejs入门demo

    demo的实例引用自:http://www.runoob.com/nodejs/nodejs-event.html, 官方文档:https://nodejs.org/dist/latest-v6.x/ ...

  8. DWR入门实例(二)

    DWR(Direct Web Remoting) DWR is a Java library that enables Java on the server and JavaScript in a b ...

  9. JDBC连接SqlServer数据库(非默认实例)方法

    一般我们在连接数据库的时候都是用的默认实例名,今天遇到了用非默认是实例名:连接代码如下(Java): URL=jdbc:microsoft:sqlserver://192.168.1.85//DEMO ...

随机推荐

  1. postman中如何传数组

    方法一: postman的传参: java接收: package com.nps.base.xue.xd.groovyEngine import com.google.gson.Gson import ...

  2. CodeForces 1166E The LCMs Must be Large

    题目链接:http://codeforces.com/problemset/problem/1166/E 说明 LCM(一个集合) 为这个集合中所有元素的最小公倍数. 如果$A \subseteq B ...

  3. LeetCode刷题笔记-BFS-二叉树层次遍历

    题目描述: 给定一个二叉树,返回其节点值自底向上的层次遍历. (即按从叶子节点所在层到根节点所在的层,逐层从左向右遍历) 例如:给定二叉树 [3,9,20,null,null,15,7], 3 / \ ...

  4. linux centos 装g++安装不了

    今天需要编译一个项目的时候在装g++都装不上, [root@master hadoop]# yum install g++ Loaded plugins: fastestmirror, refresh ...

  5. 4.8 this关键字

    /** * 测试this * @author Hank * */ /* 创建一个对象分为如下四步: 1.分配对象空间,并将对象成员变量初始化为0或空 2.执行属性值的显示初始化 3.执行构造方法 4. ...

  6. UEditor 编辑模板

    读取模板,放到ueditor中进行编辑 @model WeiXin_Shop.Models.WX_GoodsDetails @Html.Partial("_MasterPage") ...

  7. 自动化测试之sikuli调研

    调研结果 Sikuli可用于web和app的自动化测试中,操作简单,代码容易,但截图过程太过繁琐,所需要的图片内存占用量大,且sikuli的图片识别度较低,需对所要操作的图片进行精准截图. 什么是Si ...

  8. js隐式类型转换,预编译、递归、作用域,作用域链、闭包、立即执行函数、继承圣杯模式

    隐式类型转换 调用Number()当有运算符(加减乘除,求余)时,会调用Number()转为数字再运算,除了 加 当 有字符串时就变身成拼接Boolean();String(); typeof()st ...

  9. docker-compose安装及docker-compose.yml详解

    1.下载安装 [root@cx-- ~]# curl -L https://github.com/docker/compose/releases/download/1.24.1/docker-comp ...

  10. swoole手册

    https://wiki.swoole.com/wiki/ Swoole Github项目地址:https://github.com/swoole/swoole-src/ (支持请点Star) 开源中 ...