Echarts的相关问题记录与应用
一、相关问题记录:
1、对图表的div进行隐藏操作,使用hide()或display:none,重新展示时,会造成图表无法获取高度,导致图表的高宽不符合预期:
解决方法:最后调用一下resize()函数, 例如: var myCharts = echarts.init($('#id')[0]), myCharts.setOption(option) myCharts.resize();
2、饼图的大小是有radius参数决定的。参数为字符串:百分比;
------------------------------------------------------------------------------------------------------------
二、Echarts应用(集成到angularjs中):
1、html:
<div id="manage_space" class="view">
<div class="data-show content">
<div class="header">
<div class="selectType">
<select data-ng-model="queryType"
data-ng-options="x for (x, y) in queryTypes"
>
</select>
</div>
<span class="input-group-filters">
<input type="text" placeholder="输入关键词过滤" data-ng-model="keyword" />
</span>
<span>
<a class="btn btn-default btn-sm" data-ng-click="refresh()"><i class="fa fa-refresh"></i> 刷新</a>
</span>
</div>
<div class="data-content">
<div class="loader" data-ng-if="loading">正在加载...</div>
<div class="nodata-p" data-ng-if="!loading && spaces.length == 0">
<div class="nodata-c">
<small class="text-muted">抱歉,暂无数据!</small>
</div>
</div>
<ol class="ns-list-group">
<li class="ns-list-group-item-title">
<div class="col-md-3">
<div>名称</div>
</div>
<div class="col-md-3">
<div>总大小</div>
</div>
<div class="col-md-2">
<div>预警值</div>
</div>
<div class="col-md-2">
<div>最小值</div>
</div>
<div class="col-md-2">
<div>已使用</div>
</div>
<div class="clearfix"></div>
</li>
<li class="ns-list-group-item" data-ng-repeat="space in spaces | filter : ifContain">
<div class="col-md-3">
<div><a data-ng-click="showChart(space)" href="javascript:;">{{space.name}}</a></div>
</div>
<div class="col-md-3">
<div>{{space.spaceInfo.capacityGigaBytes}} G</div>
</div>
<div class="col-md-2">
<div>{{space.spaceInfo.warningBytes}} G</div>
</div>
<div class="col-md-2">
<div>{{space.spaceInfo.blockBytes}} G</div>
</div>
<div class="col-md-2">
<div>{{space.spaceInfo.usedBytes}} G</div>
</div>
<div class="clearfix"></div>
</li>
</ol>
</div>
</div>
<div id="h-handler" class="handler"></div>
<div class="charts-show">
<div class="selectType">
<select data-ng-model="chart"
data-ng-options="x for (x, y) in myCharts"
>
</select>
</div>
<div class="chart-title">
<div class="barchart-icon" data-ng-if="chart=='bar'">
<span data-ng-if="queryType=='group'" class="group-title">工作组空间使用情况</span>
<span data-ng-if="queryType=='user'" class="user-title">用户空间使用情况</span>
<ol>
<li class="normal">正常</li>
<li class="warn">警告</li>
<li class="alerted">预警</li>
<li class="surplus">剩余</li>
</ol>
</div>
<div class="piechart-icon" data-ng-if="chart=='pie'">
<span data-ng-if="queryType=='group'" class="group-title">工作组空间使用情况<br/><span>单位:GB</span></span>
<span data-ng-if="queryType=='user'" class="user-title">用户空间使用情况<br/><span>单位:GB</span></span>
<ol>
<li><span class="surpluspace">剩余</span>剩余空间</li>
<li><span class="usedspace">已用</span>已用空间</li>
</ol>
</div>
</div> <div class="bar-show col-md-11" data-ng-show="chart=='bar'" bar-charts data-source="baseunits"></div>
<div class="pie-show" data-ng-show="chart=='pie'" pie-charts data-source="baseunit"
data-ng-repeat="baseunit in baseunits"></div>
</div>
</div>
2、css
#manage_space{
margin-left: 2px;
float: left;
}
#manage_space.view{
display: inline;
}
#manage_space.view>.data-show {
padding:;
width: 50%;
height:100%;
float: left;
border: 1px solid;
border-bottom: 0px;
} #manage_space.view>.handler {
position: absolute;
left: 50%;
top:;
bottom:;
width: 3px;
background-color: transparent;
} #manage_space .charts-show{
position: absolute;
right:;
width: 50%;
left:50%;
padding:;
height:100%;
top:;
margin-top: 10px;
padding-left: 5px;
overflow: auto;
} #manage_space .header{
margin-top: 10px;
margin-bottom: 10px;
border-bottom: 1px solid;
padding-bottom: 5px;
} #manage_space .selectType{
float:left;
margin-left:10px;
} #manage_space .selectType select{
padding-right: 30px;
height:26px;
} #manage_space .header .input-group-filters {
display: inline-block;
vertical-align: middle;
margin-left: 50px;
margin-top:-5px;
} #manage_space .header span>a{
margin-top: -2px;
} #manage_space ol li{
padding-top: 5px;
padding-bottom: 5px;
} #manage_space .ns-list-group-item-title div{
font-weight:bold;
text-align: center;
} #manage_space.view>.content .ns-list-group-item {
line-height: 2.0em;
padding-top: 5px;
padding-bottom: 5px;
text-align: center;
white-space: nowrap;
} #manage_space .charts-show>.selectType{
float: none;
margin-left: 20px;
} #manage_space .charts-show>.chart-title{
float: none;
margin-left: 20px;
font-weight: bold;
margin-top: 10px;
font-size: 18px;
} .barchart-icon .group-title;.barchart-icon .user-title{
text-align: left;
display: block;
float: left;
} .barchart-icon ol{
float: right;
list-style: none;
font-weight: normal;
font-size: 8px; } .barchart-icon ol li{
padding:2px 10px;
float: left;
margin-right: 3px;
} .barchart-icon .normal{
background-color: #00FE69;
}
.barchart-icon .warn{
background-color: #FEFE1F;
}
.barchart-icon .alerted{
background-color: #FF0301;
}
.barchart-icon .surplus{
background-color: #3B9BFD;
} .piechart-icon{
text-align: center;
display: block;
} .group-title>span , .user-title>span{
font-weight: normal;
font-size: 8px;
} .piechart-icon ol{
text-align: left;
list-style: none;
margin-top: -50px;
font-weight: normal;
font-size: 10px;
} .piechart-icon ol li>span{
margin-right: 10px;
padding:0px 3px;
font-size: 6px;
}
.piechart-icon .surpluspace{
background: #C13530;
color: #C13530; }
.piechart-icon .usedspace{
background: #2E4453;
color: #2E4453;
} #manage_space .bar-show{
padding: 10px;
height: 90%;
position: absolute;
text-align: center;
margin-top: -20px;
}
#manage_space .pie-show{
padding:5px 5px 10px 10px;
float:left;
height: 30%;
width: 30%;
margin-top: -50px;
margin-bottom: 20px;
}
3、js
nsiteConsoleApp.controller('ManageSpaceController',function($scope,
$rootScope, $filter, Proxy, Message){ $scope.resetMenu('manage', 'space'); var currentStationId = $scope.managedStationId; $scope.queryType = 'group';
$scope.queryTypes = {
'工作组' :'group',
'用户 ' :'user'
};
$scope.chart = 'bar';
$scope.myCharts = {
"柱状图":'bar',
"饼图":'pie'
};
$scope.$watch('queryType',function(newV,oldV,$scope){
$scope.refresh();
});
$scope.$watch('keyword',function(newV,oldV,$scope){
if(typeof(newV) == "undefined") return;
$scope.baseunits = [];
angular.forEach($scope.spaces,function(unit){
if(unit.name.indexOf($scope.keyword) > -1){
$scope.baseunits.push(unit);
}
});
}); $scope.ifContain = function(unit){
if($scope.keyword && $scope.keyword.length>0){
return unit.name.indexOf($scope.keyword) > -1;
}
return true;
}; $scope.refresh = function(){
$scope.loading = true;
$scope.spaces = [];
if($scope.queryType === 'group'){
/* Proxy.security_lo.Group.findByParentId({ parentId: currentStationId },
function success(resp) {
$scope.loading = false;
$scope.spaces = resp;
$scope.baseunits = resp;
});*/
Proxy.security_lo.Group.queryAll({start:0, limit:1000},
function success(resp) {
$scope.loading = false;
$scope.spaces = [];
$(resp.items).each(function(i, group){
if(group.stationId = currentStationId ){
$scope.spaces.push(group);
}
});
$scope.baseunits = $scope.spaces;
}); }else{
Proxy.security_lo.User.findByParentId({ parentId: currentStationId },
function success(resp) {
$scope.loading = false;
$scope.spaces = resp;
$scope.baseunits = resp;
});
}
};
//$scope.refresh(); //展示单条数据
$scope.showChart= function(baseunit){
if(baseunit.uniqueName){
$scope.baseunits = [];
$scope.baseunits.push(baseunit);
}else{
//获取组成员
Proxy.Security.findUsersByGroupIds({
groupIds: [baseunit.id],
}, function (resp) {
if(resp[0]){
$scope.baseunits = resp[0].users;
}else{
Message.warn('此栏目下无用户!');
}
});
} }
})
.directive('barCharts',function(){
return{
restrict:'EA',
scope:{
source : '='
},
template:'<div>柱图</div>',
controller:function($scope){
},
link:function(scope,element,attr){
var chart = element.find('div')[0];
var parent = element['context'];
var width , height;
width = parent.clientWidth || 600;
height = parent.clientHeight || 400;
chart.style.width = (width- 0) +'px';
chart.style.height = (height- 0) + 'px'; scope.option = {
title:{
text:''
},
tooltip:{
trigger:'axis',
axisPointer:{
type:'shadow'
}
},
legend:{
// right:'right',
// data:['正常','警告','预警','剩余']
},
xAxis:{
type:'value',
name:'(GB)'
},
yAxis:{
type: 'category',
axisLabel:{
rotate:0,
textStyle:{
fontSize:8,
fontWeight:'bold'
}
},
data: []
},
grid: {
left: '3%',
right: '7%',
bottom: '3%',
containLabel: true
},
series:[
{
name:'已使用',
type:'bar',
stack:'存储空间',
label:{
normal:{
show:false,
position:'insideRight'
}
},
barWidth:'50%',
data:[]
},
{
name:'剩 余',
type:'bar',
stack:'存储空间',
label:{
normal:{
show:false,
position:'insideRight'
}
},
itemStyle:{
normal:{
color:'#CBCBCB'
}
},
barWidth:'50%',
data:[]
}
]
}; scope.$watch('source', function(newVal, oldVal, scope){
var baseunits = newVal;
if(typeof(baseunits) == "undefined") return;
chart.style.height = (height * (baseunits.length < 7 ? 7 : baseunits.length) / 10)+'px';
var barChart = echarts.init(chart);
//给图表赋值
scope.option.yAxis.data = [];
scope.option.series[0].data = [];
scope.option.series[1].data = [];
for (var int = baseunits.length - 1 ; int >=0; int--) {
var baseunit = baseunits[int];
scope.option.yAxis.data.push(baseunit.name);
scope.option.series[0].data.push(
{
value: baseunit.spaceInfo.usedBytes,
itemStyle:{
normal:{
color: baseunit.spaceInfo.usedBytes*100 /baseunit.spaceInfo.capacityGigaBytes > 85 ?
'#FF0301': (baseunit.spaceInfo.usedBytes*100 /baseunit.spaceInfo.capacityGigaBytes < 70) ?
'#00FA67':'#CDCD19'
}
}
}
);
scope.option.series[1].data.push((baseunit.spaceInfo.capacityGigaBytes - baseunit.spaceInfo.usedBytes)<0 ?
0:(baseunit.spaceInfo.capacityGigaBytes - baseunit.spaceInfo.usedBytes));
};
barChart.setOption(scope.option);
barChart.resize();
});
}
};
})
.directive('pieCharts',function(){
return{
restrict:'EA',
scope:{
source : '='
},
template:'<div>饼图</div>',
controller:function($scope){
},
link:function(scope,element,attr){ var chart = element.find('div')[0];
var parent = element['context'];
var width , height;
width = parent.clientWidth || 200;
height = parent.clientHeight || 200;
chart.style.width = (width - 0) +'px';
chart.style.height = (height + 0) +'px'; var pieChart = echarts.init(chart);
scope.option = {
backgroudColor:'#F2F2F2',
title : {
text: '',
x:'center',
y:'bottom',
padding:[20,0,5,0],
textStyle:{
fontSize:16
}
},
tooltip:{
trigger:'item',
formatter:'{a}<br/>{b} {c}({d}%)',
position:[-10, 10]
},
series:[
{
name:'空间使用',
type:'pie',
radius:'65%',
center:['50%','60%'],
label:{
normal:{
show : true,
position : 'inside'
}
},
data:[
{
value: 0 ,
name:'已使用',itemStyle:{
normal:{
color:'#324A5B'
}
}},
{
value: 0,
name:'未使用',
itemStyle:{
normal:{
color:'#C13530'
}
}}
],
itemStyle:{
emphasis: {
shadowBlur: 10,
shadowOffsetX: 0,
shadowColor: 'rgba(0, 0, 0, 0.5)'
}
}
}
]
}; scope.$watch('source', function(newVal, oldVal, scope){
var baseunit = newVal;
scope.option.title.text = baseunit.name;
scope.option.series[0].data[0].value = baseunit.spaceInfo.usedBytes;
scope.option.series[0].data[1].value = baseunit.spaceInfo.capacityGigaBytes - baseunit.spaceInfo.usedBytes;
pieChart.setOption(scope.option);
pieChart.resize();
});
}
};
})
4、主页:
<!DOCTYPE html>
<html lang="zh_CN" data-ng-app="nsiteConsoleApp">
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="../3rd/font-awesome/css/font-awesome.min.css">
<link rel="stylesheet" href="../3rd/bootstrap/css/bootstrap.min.css">
<link rel="stylesheet" href="../3rd/bootstrap/css/bootstrap-theme.min.css">
<link rel="stylesheet" href="css/manage/space.css">
<script src="../3rd/echarts/echarts.js"></script>
<script src="js/controllers/manage/space.js"</script>
<script src="../3rd/jquery/jquery.min.js"></script>
<script src="../3rd/bootstrap/js/bootstrap.min.js"></script>
<script src="../3rd/angular.min.js"></script>
</script>
<!-- -->
<script src="../3rd/date-ui/date-ui.js"></script>
<!-- -->
</head>
<body data-ng-controller="MainController"> <header id="nv_header" data-ng-if="session.isLogged">
<nav class="navbar navbar-inverse" role="navigation">
</nav>
</header>
<nav id="nv_left" data-ng-if="session.isLogged">
</nav>
<article id="nv_content" data-ng-view data-ng-if="session.isLogged || isLogging"></article>
<footer></footer>
</body> </html>
以上!
Echarts的相关问题记录与应用的更多相关文章
- piezo film 压电相关信息记录 (2018-05-04 更新)
piezo film 压电相关信息记录 起因需要使用 Piezo 做一些设计 http://www.te.com.cn/chn-zh/videos/transportation/piezo-film- ...
- saltstack 开发相关命令记录
SALT API开发相关命令记录. 查看当前的salt key信息salt-key -L 测试被控主机的连通性salt '*' test.ping 远程命令执行测试salt '*' cmd.run ' ...
- Vue-cli 多页相关配置记录
Vue-cli 多页相关配置记录 搭建一个顺手的MPA项目脚手架,其实根据项目的不同目录结构和打包配置都可以进行灵活的调整.这次的项目可能是包含各种客户端和管理后台在一起的综合项目所以需要将样式和脚本 ...
- echarts相关问题记录
1.图标距离容器边界 //echats options options : { //... grid : { top : 40, //距离容器上边界40像素 bottom: 30 //距离容器下边界3 ...
- Yii2的相关学习记录,前后台分离及migrate使用(七)
最近一直忙其它的(其实是懒!),将<深入理解Yii2>看了一遍,一些当初没明白的稍微明了了点,然后又看yii2的图片上传等处理.富文本.restful什么的,但由于没进行到这里,只看也不管 ...
- Yii2的相关学习记录,alert等美化、confirm异步、session中的flash及小部件的使用(六)
呃,系统自带的alert.confirm等弹出框实在是难看,作为一个颜控,这能忍? 这里我用的是kartik-v/yii2-dialog,这个是基于bootstrap3-dialog这个来做了一些常用 ...
- Yii2的相关学习记录,初始化Yii2(二)
前面已经将Yii2下载下来了,那我们就需要能实际的使用. 一.初始化,因为我都是在windows系统下,所以用cmd命令打开下载下来的Yii2的根目录.然后运行下面命令: init 会提示选择0为开发 ...
- Yii2的相关学习记录,下载Yii2(一)
原先学习过Yii1的相关知识,虽然也是半懂不懂的,但稍微的结构是了解的.现在利用晚上的时间学习下Yii2的使用,打算建一个后台管理系统,这里记录下,以免自己以后忘记. 目前已看一部分Yii2的权威指南 ...
- java 项目相关 学习记录
一位资深程序员大牛给予Java初学者的学习路线建议 [任何时期都可以好好看看] https://www.imooc.com/article/8993 https://www.jianshu.com/ ...
随机推荐
- 实现台式机redhat6.4无线网卡上网RTL8188CUS
台式机装了红帽6.4,无法无线wlan上网,特此用usb无线网卡设置 输入命令lsusb,可以看到USB无线网卡是 Realtek Semiconductor Corp. RTL8188CUS 8 ...
- 使用jlink直接烧norflash或者nandflash不借助uboot的猜想
由于喜欢折腾,我是在linux下使用jlink的,既然JLinkExe可以进行内存读写操作,loadbin等操作,并且通过指定命令文件支持批量指令输入,那么首先jlink是可以直接访问内部存储器的,包 ...
- 大话设计模式C++版——装饰模式
女人常说男人喜新厌旧,只见新人笑,那闻旧人哭,但装饰模式(Decorator)却是一种结交新朋友不忘老朋友的设计模式,非常适合去古代当老公(现代是不行的,因为只能娶一个老婆了).装饰模式的本质是每一个 ...
- file_get_contents模仿浏览器头(user_agent)获取数据
本篇文章是对file_get_contents模仿浏览器头(user_agent)获取数据进行了详细的分析介绍,需要的朋友参考下 什么是user agentUser Agent中文名为用户代理 ...
- 洛谷P1538迎春舞会之数字舞蹈
题目背景 HNSDFZ的同学们为了庆祝春节,准备排练一场舞会. 题目描述 在越来越讲究合作的时代,人们注意的更多的不是个人物的舞姿,而是集体的排列. 为了配合每年的倒计时,同学们决定排出——“数字舞蹈 ...
- 网络之OSI&&TCP/IP比较
共同点: 1.OSI和TCP/IP都采用了层次结构的概念 2.都能够提供面向链接(TCP)和无链接(UDP)两种通信服务机制 不同点: 1.前者7层,后者两层 2.对可靠性要求不同,TCP/IP要求高 ...
- 计算2的N次方&&计算e
2的N次方 注意:这里在处理的时候并没有用循环来处理,而是用移位的做法. n<<4 就是 n*2^4 ,所以在本例中只需要写 1<<time (time是要求的 ...
- Linux系统资源使用情况
概述: 用 'top -i' 看看有多少进程处于 Running 状态,可能系统存在内存或 I/O 瓶颈,用 free 看看系统内存使用情况,swap 是否被占用很多,用 iostat 看看 I/O ...
- angular的uiRouter服务学习(5) --- $state.includes()方法
$state.includes方法用于判断当前激活状态是否是指定的状态或者是指定状态的子状态. $state.includes(stateOrName,params,options) $state.i ...
- java script 确认框
<input name="Submit" type="submit" class="inputedit" value="删除 ...