angular-gridster2使用
1、安装:npm install angular-gridster2 --save
2、引入
3、html代码
<div id="fullscreen" style="position:relative;padding-top:20px;background: #fff;" >
<em class="fa fa-compress hand " style="position: absolute;right: 0px;top: 0px; font-size: 30px;" (click)="zoomItem()" (touchstart)="zoomItem()" title="缩小"></em>
<em class="fa fa-arrow-circle-left hand z-index" style="position: absolute;left: 0px;top: 50%; font-size:30px; z-index:99999999;" (click)="upWard()" (touchstart)="upWard()" title="向上"></em>
<em class="fa fa-arrow-circle-right hand z-index" style="position: absolute;right: 0px;top: 50%; font-size:30px; z-index:99999999;" (click)="down()" (touchstart)="down()" title="向下"></em>
<!-- <div [ngSwitch]="fullscreenIndex">
<div *ngSwitchCase="'demo1'" >
<div echarts [options]="echartsOption1" id="fullscreenEcharts" style="height: 600px;"></div>
</div>
<div *ngSwitchCase="'demo2'" >
<div echarts [options]="echartsOption2" id="fullscreenEcharts" style="height: 600px;"></div>
</div>
</div> -->
</div>
<!--ignoreContentClass: 'gridster-item-content', // default content class to ignore the drag event from -->
<gridster [options]="options" style="height:650px;" id="gridster">
<gridster-item [item]="item.view" *ngFor="let item of dashboard;let i =index;">
<!-- your content here -->
<div class="fs-md" style="padding-top: 5px;">
<label class="item-label gridster-item-content">{{item.label}}</label>
<div style="position:absolute;top: 0px;right:0px;display: flex;">
<div class="float-right pr-10 hand gridster-item-content" style="cursor: pointer;padding-right: 10px;" (click)="zoomItem($event, item)"
(touchstart)="zoomItem($event, item)" mdTooltip="Remove" title="放大">
<em class="fa fa-expand" title="放大"></em>
<i nz-icon nzType="fullscreen" nzTheme="outline"></i>
</div>
<div class="float-right pr-10 hand gridster-item-content" style="cursor: pointer;padding-right: 10px;" (click)="removeItem($event, item)"
(touchstart)="removeItem($event, item)" mdTooltip="Remove">
<em class="anticon anticon-close" title="删除"></em>
<i nz-icon nzType="close" nzTheme="outline"></i>
</div>
<div class="float-right pr-10 hand" style="cursor: pointer;padding-right: 10px;" >
<em class="fa fa-arrows" title="拖拽"></em>
<i nz-icon nzType="ungroup" nzTheme="outline"></i>
</div>
</div>
<div [ngSwitch]="i+1" class="gridster-item-content">
<div *ngSwitchCase="'1'">
<div echarts [options]="echartsOption1" class="demo-chart" (chartInit)="onChartInit($event,i+1)" id="demo1" ></div>
</div>
<div *ngSwitchCase="'2'" >
<div echarts [options]="echartsOption2" class="demo-chart" (chartInit)="onChartInit($event,i+1)" id="demo2"></div>
</div>
<div *ngSwitchCase="'3'" >
item content {{i+1}}
</div>
<div *ngSwitchCase="'4'" >
item content {{i+1}}
</div>
<div *ngSwitchCase="'5'" >
item content {{i+1}}
</div>
<div *ngSwitchCase="'6'" >
item content {{i+1}}
</div>
<div *ngSwitchCase="'7'" >
item content {{i+1}}
</div>
<div *ngSwitchCase="'8'">
item content {{i+1}}
</div>
</div>
</div>
</gridster-item>
</gridster>
4、ts代码
import { Component, OnInit } from '@angular/core';
import {GridsterConfig,GridsterItem } from "angular-gridster2";
import {NgxEchartsModule} from "ngx-echarts";
@Component({
selector: 'app-table',
templateUrl: './table.component.html',
styleUrls: ['./table.component.less']
})
export class TableComponent implements OnInit {
public options: GridsterConfig;
public dashboard;
private fullscreen:string="fullscreen";
private fullscreenIndex:string="demo1";
public echartsInstance1:any;
public echartsInstance2:any;
public echartsOption1: any;
public echartsOption2: any;
static itemChange(item, itemComponent) {
console.info('itemChanged', item, itemComponent);
}
static itemResize(item, itemComponent) {
console.info('itemResized', item, itemComponent);
}
constructor(
) { }
webSite: any[] = [ ];
salesData: any[] = [ ];
offlineChartData: any[] = [];
ngOnInit() {
let self = this;
this.echartsOption1 = {
title: {
text: '折线图堆叠'
},
tooltip: {
trigger: 'axis'
},
grid: {
left: '3%',
right: '4%',
bottom: '3%',
containLabel: true
},
toolbox: {
feature: {
saveAsImage: {}
},
right:'10%'
},
xAxis: {
type: 'category',
boundaryGap: false,
data: ['周一','周二','周三','周四','周五','周六','周日']
},
yAxis: {
type: 'value'
},
series: [
{
name:'邮件营销',
type:'line',
stack: '总量',
data:[120, 132, 101, 134, 90, 230, 210]
},
{
name:'联盟广告',
type:'line',
stack: '总量',
data:[220, 182, 191, 234, 290, 330, 310]
},
{
name:'视频广告',
type:'line',
stack: '总量',
data:[150, 232, 201, 154, 190, 330, 410]
},
{
name:'直接访问',
type:'line',
stack: '总量',
data:[320, 332, 301, 334, 390, 330, 320]
},
{
name:'搜索引擎',
type:'line',
stack: '总量',
data:[820, 932, 901, 934, 1290, 1330, 1320]
}
]
};
this.echartsOption2 = {
title: {
text: '折线图堆叠'
},
tooltip: {
trigger: 'axis'
},
grid: {
left: '3%',
right: '4%',
bottom: '3%',
containLabel: true
},
toolbox: {
feature: {
saveAsImage: {}
},
right:'10%'
},
xAxis: {
type: 'category',
boundaryGap: false,
data: ['周一','周二','周三','周四','周五','周六','周日']
},
yAxis: {
type: 'value'
},
series: [
{
name:'邮件营销',
type:'line',
stack: '总量',
data:[120, 132, 101, 134, 90, 230, 210]
},
]
};
/* this.http.get('/chart').subscribe((res: any) => {
this.webSite = res.visitData.slice(0, 10);
this.salesData = res.salesData;
this.offlineChartData = res.offlineChartData;
}); */
this.options = {
gridType: 'fit',
compactType: 'none',/*对齐类型*/
itemChangeCallback:function (item,itemComponent){
//console.info('itemChanged', item, itemComponent);
let echarts = document.getElementById(`${item.id}`);
// const chart = new G2.Chart({
// container: document.getElementById(`${item.id}`),
// forceFit: true,
// height: itemComponent.height-30
// });
// chart.forceFit()
if(echarts){/*在gridster2 Change的时候出发echarts的resize方法*/
echarts.style.width = itemComponent.width+'px';
echarts.style.height = itemComponent.height-30+'px';
// /*根据不同的模块 重置相应的图*/
let a = {"demo1":self.echartsInstance1,"demo2":self.echartsInstance2}
a[item.id].resize();
}
console.log('itemChangeCallback', item, itemComponent);
},
itemResizeCallback:function (item, itemComponent){
// const chart = new G2.Chart({
// container: document.getElementById(`${item.id}`),
// forceFit: true,
// height: itemComponent.height-30
// });
//chart.forceFit()
let echarts = document.getElementById(`${item.id}`);
if(echarts){/*在gridster2 resize的时候出发echarts的resize方法*/
echarts.style.width = itemComponent.width+'px';
echarts.style.height = itemComponent.height-30+'px';
// /*根据不同的模块 重置相应的图*/
let a = {"demo1":self.echartsInstance1,"demo2":self.echartsInstance2};
a[item.id].resize();
}
//console.log('itemResize', item, itemComponent);
console.log('itemResizeCallback', item, itemComponent);
},
margin: 10,
outerMargin: true,
minCols: 1,
maxCols: 8,
minRows: 1,
maxRows: 10,
maxItemCols: 5,
minItemCols: 1,
maxItemRows: 5,
minItemRows: 1,
defaultItemCols: 1,
defaultItemRows: 1,
fixedColWidth: 250,
fixedRowHeight: 250,
draggable: { /*是否可拖拽*/
enabled: true,
/*stop: AppComponent.eventStop*/
},
resizable: { /*是否可以缩放*/
enabled: true,
/*stop: AppComponent.eventStop*/
},
swap: false,
displayGrid: 'onDrag&Resize' /*显示行和列的背景网格。选项:'永远' 缩放和拖拽时| 从不*/
};
this.dashboard =[
{
'label':'item1',
'view': {cols: 2, rows: 1, y: 0, x: 0,id:"demo1",hasContent: true}
},
{'label':'item2',
view:{cols: 2, rows: 2, y: 0, x: 2,id:"demo2"},
},
{'label':'item3',
view:{cols: 1, rows: 1, y: 0, x: 4,id:"demo3"},
},
{'label':'item4',
view:{cols: 1, rows: 1, y: 0, x: 5,id:"demo4"},
},
{'label':'item5',
view:{cols: 1, rows: 1, y: 1, x: 0,id:"demo5"},
},
{'label':'item6',
view:{cols: 1, rows: 1, y: 1, x: 1,id:"demo6"},
},
{'label':'item7',
view:{cols: 2, rows: 2, y: 1, x: 5, label: 'Min rows & cols = 2',id:"demo7"},
//view:{cols: 2, rows: 2, y: 1, x: 5, minItemRows: 2, minItemCols: 2, label: 'Min rows & cols = 2'},
},
{'label':'item8',
//view:{cols: 2, rows: 2, y: 2, x: 0, maxItemRows: 2, maxItemCols: 2, label: 'Max rows & cols = 2'},
view:{cols: 2, rows: 2, y: 2, x: 0, label: 'Max rows & cols = 2',id:"demo8"},
},
// {'label':'item9',
// view:{cols: 2, rows: 1, y: 2, x: 2, dragEnabled: true, resizeEnabled: true, label: 'Drag&Resize Enabled'},
// },
// {'label':'item10',
// view:{cols: 1, rows: 1, y: 2, x: 4, dragEnabled: true, resizeEnabled: true, label: 'Drag&Resize Disabled'},
// },
// {'label':'item11',
// view:{cols: 1, rows: 1, y: 0, x: 6},
// },
];
}
ngAfterViewInit(){
let fullscreen = document.getElementById('fullscreen');
fullscreen.style.display="none";
fullscreen.style.width = (document.body.clientWidth-250)+'px';
//fullscreen.style.height = (document.body.clientHeight-150)+'px';
fullscreen.style.height = 650+'px';
}
changedOptions() {
if (this.options.api && this.options.api.optionsChanged) {
this.options.api.optionsChanged();
}
}
/*初始化*/
onChartInit(e: any,i:number) {
//console.log(i);
if( i===1 ){
this.echartsInstance1 = e;
}else if( i===2 ){
this.echartsInstance2 = e;
}
//console.log('on chart init:', e);
}
removeItem(event?,item?) {
this.dashboard.splice(this.dashboard.indexOf(item), 1);
}
// addItem() {
// this.dashboard.push({});
// }
zoomItem(event?,item?){
if(item){
/*ngSwitchCase 赋值 用来判断*/
this.fullscreenIndex=item.view.id;
let fullscreenEcharts = document.getElementById('fullscreenEcharts');
/*根据屏幕宽度设置 放大后的echarts 宽高*/
if(fullscreenEcharts){
fullscreenEcharts.style.width = (document.body.clientWidth-275)+'px';
fullscreenEcharts.style.height = (document.body.clientHeight-150)+'px';
let a = {"demo1":this.echartsInstance1,"demo2":this.echartsInstance2};
a[item.view.id].resize();
}
}
let fullscreen = document.getElementById('fullscreen');
let gridster = document.getElementById('gridster');
if(this.fullscreen === "fullscreen"){
fullscreen.style.display="block";
gridster.style.display="none";
this.fullscreen = "fullscreen_exit" ;
}else{
fullscreen.style.display="none";
gridster.style.display="block";
this.fullscreen = "fullscreen";
}
}
/*向上*/
upWard() {
//this.fullscreenIndex;
console.log(this.fullscreenIndex);
let num= parseInt(this.fullscreenIndex.substr(this.fullscreenIndex.length-1,1));
// console.log(typeof(num));
if (num > 1){
num =num - 1;
}else{
num = 8;
}
this.fullscreenIndex = 'demo' +num;
//console.log(this.fullscreenIndex.substr(this.fullscreenIndex.length-1,1));
console.log("upWard");
}
/*向下*/
down() {
console.log(this.fullscreenIndex);
let num= parseInt(this.fullscreenIndex.substr(this.fullscreenIndex.length-1,1));
// console.log(typeof(num));
if (num < 8){
num =num + 1;
}else{
num = 1;
}
this.fullscreenIndex = 'demo' +num;
//console.log(this.fullscreenIndex.substr(this.fullscreenIndex.length-1,1));
console.log("down");
}
}
5、结果
6、参考
https://tiberiuzuld.github.io/angular-gridster2/api
https://blog.csdn.net/wen_binobject/article/details/80309197
angular-gridster2使用的更多相关文章
- Angular杂谈系列1-如何在Angular2中使用jQuery及其插件
jQuery,让我们对dom的操作更加便捷.由于其易用性和可扩展性,jQuer也迅速风靡全球,各种插件也是目不暇接. 我相信很多人并不能直接远离jQuery去做前端,因为它太好用了,我们以前做的东西大 ...
- Angular企业级开发(5)-项目框架搭建
1.AngularJS Seed项目目录结构 AngularJS官方网站提供了一个angular-phonecat项目,另外一个就是Angular-Seed项目.所以大多数团队会基于Angular-S ...
- TypeScript: Angular 2 的秘密武器(译)
本文整理自Dan Wahlin在ng-conf上的talk.原视频地址: https://www.youtube.com/watch?v=e3djIqAGqZo 开场白 开场白主要分为三部分: 感谢了 ...
- angular实现统一的消息服务
后台API返回的消息怎么显示更优雅,怎么处理才更简洁?看看这个效果怎么样? 自定义指令和服务实现 自定义指令和服务实现消息自动显示在页面的顶部,3秒之后消失 1. 显示消息 这种显示消息的方式是不是有 ...
- div实现自适应高度的textarea,实现angular双向绑定
相信不少同学模拟过腾讯的QQ做一个聊天应用,至少我是其中一个. 过程中我遇到的一个问题就是QQ输入框,自适应高度,最高高度为3row. 如果你也像我一样打算使用textarea,那么很抱歉,你一开始就 ...
- Angular企业级开发-AngularJS1.x学习路径
博客目录 有链接的表明已经完成了,其他的正在建设中. 1.AngularJS简介 2.搭建Angular开发环境 3.Angular MVC实现 4.[Angular项目目录结构] 5.[SPA介绍] ...
- Angular企业级开发(4)-ngResource和REST介绍
一.RESTful介绍 RESTful维基百科 REST(表征性状态传输,Representational State Transfer)是Roy Fielding博士在2000年他的博士论文中提出来 ...
- Angular企业级开发(3)-Angular MVC实现
1.MVC介绍 Model-View-Controller 在20世纪80年代为程序语言Smalltalk发明的一种软件架构.MVC模式的目的是实现一种动态的程序设计,使后续对程序的修改和扩展简化,并 ...
- Angular企业级开发(2)-搭建Angular开发环境
1.集成开发环境 个人或团队开发AngularJS项目时,有很多JavaScript编辑器可以选择.使用优秀的集成开发环境(Integrated Development Environment)能节省 ...
- 前端MVC学习总结(一)——MVC概要与angular概要、模板与数据绑定
一.前端MVC概要 1.1.库与框架的区别 框架是一个软件的半成品,在全局范围内给了大的约束.库是工具,在单点上给我们提供功能.框架是依赖库的.AngularJS是框架而jQuery则是库. 1.2. ...
随机推荐
- docker停止所有窗容器
docker中 启动所有的容器命令docker start $(docker ps -a | awk '{ print $1}' | tail -n +2) docker中 关闭所有的容器命令dock ...
- Vue案例——todolist
最近在学习vue,实现todolist案例,实现效果如下: 该案例分为四个部分:header为输入框,body为列表,item是列表中的条目,footer为最下方的统计. 实现步骤: ①创建项目 vu ...
- 【git】3.3 git分支-分支管理
资料来源 (1) https://git-scm.com/book/zh/v2/Git-%E5%88%86%E6%94%AF-%E5%88%86%E6%94%AF%E7%AE%A1%E7%90%86 ...
- IBM服务器的2种IMM和1种raid管理方式
IMM两种进入方式和Raid管理软件 前面板IMM管理接口: 用网线连接服务器前置面板的管理接口到其他 PC 或笔记本,然后 PC 或笔记本的 IP 地址配置为 192.168.70.0/24 ...
- Fortran笔记之过程重载,多态,泛型编程
参考自Introduction to Modern Fortran for the Earth System Sciences 过程重载 OOP中的另一个重要技术是过程重载(Procedure Ove ...
- laravel Auth的使用
最新的文档是使用的 laravel/jetstream 扩展包,旧版本中的 php artisan make:auth 命令在新版本中已不能用,但是此博客没有使用文档提供的扩展包,而是使用的是lara ...
- Rocky8.6软raid
.tdi_3.td-a-rec { text-align: center } .tdi_3 .td-element-style { z-index: -1 } .tdi_3.td-a-rec-img ...
- RSA 非对称加密
原文链接:https://www.jianshu.com/p/d56a72013392 RSA 是一种非对称加密算法,在实际业务中经常使用此算法对数据进行加密.但是它的加解密速度较慢,不太适用于高并发 ...
- ComPiler200002:Growing a Compiler
http://www.cs.dartmouth.edu/~mckeeman/cs48/mxcom/gem/html/GrowingCompiler.html by Bill McKeeman and ...
- linux查看指定时间段日志
1.查看时间段日志:sed -n '/起始时间/,/结束时间/p' 日志文件 sed -n '/2021-05-21 10:08/,/2021-05-21 10:09/p' nohup.out2.指定 ...