Angualr2 ChartModle图表

1.ts代码
import { Component, OnInit, OnDestroy } from '@angular/core';
import { Http, Headers } from '@angular/http';
import { Observable } from 'rxjs/Rx';
import { AlertService } from 'ng-jhipster';
import { ITEMS_PER_PAGE, Principal } from '../shared'; // 分页设置,权限验证等
import { API_URL } from '../app.constants';
import { TreeModule, TreeNode } from 'primeng/primeng';
import { WrRvRecQuery } from './wr-RvRecQuery.model';
import { UIChart, ChartModule } from 'primeng/primeng';

 

@Component({
selector: 'wr-rv-rec-query',
styles: [`
p-tree{
float:left;
margin-right:0.5rem;
}
p-datatable{
display:flex;
}
.form-inline button{
margin-left:0.5rem;
}
h2{
margin:0.5rem 0;
}

 

.data-table-wrap p-tree{
float: left;
height: 50rem;
margin-right: 1rem;
}
:host >>> .ui-tree{
height: 100%;
}
.areaTable{
display: flex;
}
:host >>> .col-button{
text-align:center;
}
:host >>> .col-button button{
margin:0.5rem 0;
}
:host >>> .data-table-search{
display: flex;
margin-top:0.5rem;
margin-bottom:0.5rem;
}
:host >>> .form-group:nth-child(2){
margin:0 1rem;
}
:host >>> .form-inline{
flex:1;
-webkit-box-flex:1;
}
:host >>> .modal-dialog{
margin-top:15%;
}
p-calendar{
display: -webkit-box;
-webkit-box-flex: 1;
}
:host >>> .dialog-datepick{
display: -webkit-box;
-webkit-box-flex: 1;
}
:host >>> .ui-inputtext {
display: -webkit-box;
padding: .5rem .75rem;
font-size: 1rem;
line-height: 1.25;
}
:host >>> .btn-update{
position: absolute;
right: 25px;
top: 0;
border-top-left-radius: 0;
border-bottom-left-radius: 0;
}
 
`],
templateUrl: './wr-rvRecQuery.component.html'
})
export class WrRvRecQueryComponent implements OnInit, OnDestroy {
chartTitle: any;
pieChart: UIChart;
barChart: UIChart;
parentCode: string;
// 河段树选择的节点
selectedNode: TreeNode;
// 查询条件
query: any = {};
queryChar: any = {};
wrRvRecQuerys: WrRvRecQuery[];
wrRvRecQueryChar: WrRvRecQuery[];
itemsPerPage: number = ITEMS_PER_PAGE;
totalRecords: number;
sortBy: string;
page: number;
loading: boolean = true;
loadingChar: boolean = false;
data: any;
barData: any;
pieData: any;

 

/**
* 巡河统计构造函数
* @param http
* @param alertService
*/
constructor(private http: Http,
private alertService: AlertService) { }
/**
* 页面初期加载
*/
ngOnInit() {
// 示例里面使用荣昌区,实际用的时候应该是根据登录人的所在区域来获取
this.parentCode = '500153000000';
this.query.addvcdPath = '/500153000000';
//this.query.l = 3;
//图表
this.defaultChart();
}

 

showChar(RvRecQuery, pieChart: UIChart, barChart: UIChart) {
this.chartTitle = RvRecQuery.addvnm;
this.pieChart = pieChart;
this.barChart = barChart;
if (RvRecQuery.type == 1) {
this.queryChar.addvcdPath = RvRecQuery.addvcdPath;
this.queryChar.l = RvRecQuery.l + 1;
this.queryChar.type = 1;
}
if (RvRecQuery.type == 2) {
this.queryChar.addvcdPath = RvRecQuery.addvcdPath;
this.queryChar.rvId = RvRecQuery.addvcd;
this.queryChar.l = RvRecQuery.l + 1;
this.queryChar.type = 2;
}
if (RvRecQuery.type == 3) {
this.queryChar.addvcdPath = RvRecQuery.addvcdPath;
this.queryChar.l = RvRecQuery.l + 1;
this.queryChar.type = 3;
}
this.loadDataChar();

 

//pieData.refresh();
}

 

/**
* 页面销毁时的操作
*/
ngOnDestroy() {

 

}

 

/**
* 河段树的节点选择事件
* @param node 选中的树节点
*/
onNodeSelect(node) {
this.selectedNode = node;
this.query.l = null;
this.query.type = node.type;
if (node.type == 1) {
// 表示选择的是行政区划
this.query.addvcdPath = node.addvcdPath;
}
else if (node.type == 2) {
// 选择的是河流信息
this.query.addvcdPath = node.addvcdPath;
this.query.rvId = node.rvCd;
}
else {
// 选择的是河段信息
this.query.addvcdPath = node.rvSegIdPath;
}

 

// 设置pageIndex到第一页
this.page = 0;
this.loadData();
}

 

/**
* 搜索
*/
search() {
// TODO 这里搜索的时候需要组织搜索条件
this.page = 0; // 搜索的时候重置分页
this.loadData();
}

 

/**
* 表格的自动加载
*/
lazyLoad(e, pieChart: UIChart, barChart: UIChart) {
this.pieChart = pieChart;
this.barChart = barChart;
//this.sortBy = e.sortField ? e.sortField + ' ' + (e.sortOrder === 1 ? 'asc' : 'desc') : null;
this.page = e.first / e.rows;
console.log(this.page);
// 树节点加载出来以后再进行grid的加载
if (this.selectedNode != null) {
this.loadData();
}
}

 

/**
* 加载数据
*/
loadData() {
this.loading = true;
let body = this.query || {};
let options = {
headers: new Headers({
pageIndex: this.page,
pageSize: this.itemsPerPage,
//orderBy: this.sortBy
})
};
return this.http.post(`${API_URL}/api/rvCount/page`, body, options)
.subscribe(
(res) => this.onSuccess(res.json(), res.headers),
(res) => this.onError(res.json()));
}

 

onSuccess(data, headers) {
this.loading = false;
if (+data.responseCode !== 100) {
this.alertService.error(data.messageList[0].key, data.messageList[0].message, null);
return;
}

 

this.wrRvRecQuerys = data.a0804F0004RespL001List;
this.totalRecords = data.pageControllerInfo.totalRecordCount;
if (data.a0804F0004RespL001List != null && data.a0804F0004RespL001List.length > 0) {
let RvRecQuery: any = data.a0804F0004RespL001List[0];
this.chartTitle = RvRecQuery.addvnm;
if (RvRecQuery.type == 1) {
this.queryChar.addvcdPath = RvRecQuery.addvcdPath;
this.queryChar.l = RvRecQuery.l + 1;
this.queryChar.type = 1;
}
if (RvRecQuery.type == 2) {
this.queryChar.addvcdPath = RvRecQuery.addvcdPath;
this.queryChar.rvId = RvRecQuery.addvcd;
this.queryChar.l = RvRecQuery.l + 1;
this.queryChar.type = 2;
}
if (RvRecQuery.type == 3) {
this.queryChar.addvcdPath = RvRecQuery.addvcdPath;
this.queryChar.l = RvRecQuery.l + 1;
this.queryChar.type = 3;
}
this.loadDataChar();
} else {
this. defaultChart();
if (this.pieChart != null) {
this.pieChart.data = this.pieData;
this.pieChart.reinit();
}
if (this.barChart != null) {
this.barChart.data = this.barData;
this.barChart.reinit();
}
}
}

 

onError(error) {
this.loading = false;
this.alertService.error(error.error, error.message, null);
}

 

/**
* 加载图表数据
*/
loadDataChar() {
this.loading = true;

 

let body = this.queryChar || {};
let options = {
headers: new Headers({
//pageIndex: this.page,
//pageSize: this.itemsPerPage,
//orderBy: this.sortBy
})
};
return this.http.post(`${API_URL}/api/rvCount/page`, body, options)
.subscribe(
(res) => this.onSuccessChar(res.json(), res.headers),
(res) => this.onErrorChar(res.json()));
}

 

onSuccessChar(data, headers) {
this.loading = false;
if (+data.responseCode !== 100) {
this.alertService.error(data.messageList[0].key, data.messageList[0].message, null);
return;
}

 

this.wrRvRecQueryChar = data.a0804F0004RespL001List;

 

let piex: any = [];
let piey: any = [];

 

for (let i = 0; i < this.wrRvRecQueryChar.length; i++) {
piex.push(this.wrRvRecQueryChar[i].addvnm);
piey.push(this.wrRvRecQueryChar[i].sbCount);
}
this.pieData = {
labels: piex,
datasets: [
{
data: piey,
backgroundColor: [
"#FF6384", "#36A2EB", "#FFCE56", "#6495ED", "#00FFFF",
"#1E90FF", "#00FF7F", "#008080", "#66CDAA", "#008B8B",
"#BDB76B", "#B8860B", "#00CEDE", "#696969", "#20B2AA",
"#CC9999", "#003399", "#993333", "#0099CC", "#EEE8AA",
"#003366", "#FFFFCC", "#FFCCFF", "#99CCFF", "#32CD32",
"#99CC33", "#CCCCFF", "#0000FF", "#191970", "#ADFF2F"
],
hoverBackgroundColor: [
"#FF6384", "#36A2EB", "#FFCE56", "#6495ED", "#00FFFF",
"#1E90FF", "#00FF7F", "#008080", "#66CDAA", "#008B8B",
"#BDB76B", "#B8860B", "#00CEDE", "#696969", "#20B2AA",
"#CC9999", "#003399", "#993333", "#0099CC", "#EEE8AA",
"#003366", "#FFFFCC", "#FFCCFF", "#99CCFF", "#32CD32",
"#99CC33", "#CCCCFF", "#0000FF", "#191970", "#ADFF2F"
]
}]
}
if (this.pieChart != null) {
this.pieChart.data = this.pieData;
this.pieChart.reinit();
}

 

this.barData = {
labels: piex,
datasets: [
{
label: this.chartTitle,
backgroundColor: '#42A5F5',
borderColor: '#1E88E5',
data: piey
}
]
}
if (this.barChart != null) {
this.barChart.data = this.barData;
this.barChart.reinit();
}
this.loadingChar = true;
//this.totalRecords = data.pageControllerInfo.totalRecordCount;
}

 

onErrorChar(error) {
this.loading = false;
this.alertService.error(error.error, error.message, null);
}

 

//置空图表
defaultChart(){
this.barData = {
labels: [],
datasets: [
{
label: '',
backgroundColor: '#42A5F5',
borderColor: '#1E88E5',
data: []
}

 

]
}
this.pieData = {
labels: [],
datasets: [
{
data: [],
backgroundColor: [
"#FF6384",
"#36A2EB",
"#FFCE56"
],
hoverBackgroundColor: [
"#FF6384",
"#36A2EB",
"#FFCE56"
]
}]
}
}
}
 
 
2.html 页面
 
<div>
<h2>
<span>巡河统计</span>
</h2>
<jhi-alert></jhi-alert>
<div class="data-table-wrap">
<rv-seg [parentCode]="parentCode" (onNodeSelect)="onNodeSelect($event)"></rv-seg>
<div class="data-table-loading" *ngIf="loading">
<i class="loading"></i>
</div>
<div class="data-table-search">
<form class="form-inline" (ngSubmit)="search()">
<div class="form-group">
<label>开始时间:</label>从
<p-calendar [styleClass]="'dialog-datepick'" inputStyleClass="form-control" name="beginTm" [(ngModel)]="query.beginTm" dateFormat="yy-mm-dd">
</p-calendar>
<p-calendar [styleClass]="'dialog-datepick'" inputStyleClass="form-control" name="endTm" [(ngModel)]="query.endTm" dateFormat="yy-mm-dd">
</p-calendar>
</div>
<button type="submit" class="btn btn-primary">搜索</button>
</form>

</div>

<p-dataTable #dt [value]="wrRvRecQuerys" [lazy]="true" [rows]="itemsPerPage" [paginator]="true" [totalRecords]="totalRecords"
emptyMessage="没有记录" class="areaTable" (onLazyLoad)="lazyLoad($event,pieChart,barChart)">
<p-column field="addvcd" header="区域" [hidden]="true"></p-column>
<p-column field="l" header="层级" [hidden]="true"></p-column>
<p-column field="type" header="类型" [hidden]="true"></p-column>
<p-column field="addvcdPath" header="区域Path" [hidden]="true"></p-column>
<p-column field="addvnm" header="区域名称"></p-column>
<p-column field="jhCount" header="计划次数" [style]="{'width':'120px'}"></p-column>
<p-column field="sjCount" header="实际次数" [style]="{'width':'120px'}"></p-column>
<p-column field="sbCount" header="上报次数" [style]="{'width':'120px'}"></p-column>
<p-column field="caozuo" header="操作" styleClass="col-button" [style]="{'width':'300px'}">
<template let-WrRvRecQuery="rowData" pTemplate="body">
<button type="button" pButton label="查看" (click)="showChar(WrRvRecQuery,pieChart,barChart)"></button>
</template>
</p-column>
</p-dataTable>
<p-chart type="bar" #barChart [data]="barData"></p-chart>
<p-chart type="pie" #pieChart [data]="pieData"></p-chart>
</div>
</div>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
提供的源码资源涵盖了Java应用等多个领域,每个领域都包含了丰富的实例和项目。这些源码都是基于各自平台的最新技术和标准编写,确保了在对应环境下能够无缝运行。同时,源码中配备了详细的注释和文档,帮助用户快速理解代码结构和实现逻辑。 适用人群: 适合毕业设计、课程设计作业。这些源码资源特别适合大学生群体。无论你是计算机相关专业的学生,还是对其他领域编程感兴趣的学生,这些资源都能为你提供宝贵的学习和实践机会。通过学习和运行这些源码,你可以掌握各平台开发的基础知识,提升编程能力和项目实战经验。 使用场景及目标: 在学习阶段,你可以利用这些源码资源进行课程实践、课外项目或毕业设计。通过分析和运行源码,你将深入了解各平台开发的技术细节和最佳实践,逐步培养起自己的项目开发和问题解决能力。此外,在求职或创业过程中,具备跨平台开发能力的大学生将更具竞争力。 其他说明: 为了确保源码资源的可运行性和易用性,特别注意了以下几点:首先,每份源码都提供了详细的运行环境和依赖说明,确保用户能够轻松搭建起开发环境;其次,源码中的注释和文档都非常完善,方便用户快速上手和理解代码;最后,我会定期更新这些源码资源,以适应各平台技术的最新发展和市场需求。 所有源码均经过严格测试,可以直接运行,可以放心下载使用。有任何使用问题欢迎随时与博主沟通,第一时间进行解答!

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

对雪书空武

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值