博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
最基础eacharts图带数字,百分比,tab切换
阅读量:5170 次
发布时间:2019-06-13

本文共 3481 字,大约阅读时间需要 11 分钟。

 

 切换tab按钮通过显示隐藏展示不同charts图

html部分

<div class="panel-run-status">
<div class="panel panel-default">
<div class="panel-heading">
<span>运行概况</span>
</div>
<div class="tab-status">
<span class="activeStatus rdsInstance">
<i class="iconfont icon-instance"></i>
<i>实例</i>
</span>
<span class="rdsServer">
<i class="iconfont icon-fuwuqi1"></i>
<i>服务器</i>
</span>
<span class="rdsMiddle">
<i class="iconfont icon-zhongjianjian"></i>
<i>中间件</i>
</span>
</div>
<div class="panel-body no-padding-left" id="runStatus">
</div>
<div class="panel-body no-padding-left hidden" id="runServer">
</div>
<div class="panel-body no-padding-left hidden" id="runMiddleware">
</div>
</div>
</div>
 

其中一个charts图,另外两个图,方法类似,就像平时画eacharts图一样,再写两个

var spNum = 5;

var data = [{count:1,name:'故障',status:'1'},{count:2,name:'异常',status:'2'},{count:3,name:'预警',status:'3'},{count:4,name:'正常',status:'4'}]
var honorData4 = [];
var myColor = ["#F25B76","#F4D943","#F6BF60", "#5ECB9B"];
var legendData = [],
honorXAxisData = ['故障','预警','异常','正常'];
var sumData1 = null;
data.map(function(item, y) {
honorData4.push(item.count)
sumData1+=item.count
console.log(sumData1)
});
var isMax =sumData1;
var _max = sumData1;
var bjData1 = [isMax, isMax, isMax, isMax];
var fomatter_fn = function(v) {
console.log(v)
if(v.value==0){
v.value = ''
return (v.value='')
}else{
return (v.value)
}
}
var _label = {
normal: {
show: true,
position: 'inside',
formatter: fomatter_fn,
textStyle: {
color: '#fff',
fontSize: 12
}
}
};
var option = {
tooltip: {
trigger: "axis",
axisPointer: {
type: "none"
},
borderColor: "#ddd",
textStyle: {
fontSize: 14
},
formatter: function(p) {
var relVal = p[0].name;
var sum = 0;
for (var z = 0; z < p.length; z++) {
if (!(p[z].seriesName == 1001 || p[z].seriesName == 1000)) {
sum += p[z].value;
}
}
for (var i = 0; i < p.length; i++) {
if (!(p[i].seriesName == 1001 || p[i].seriesName == 1000)) {
relVal += "<br>" + p[i].marker + p[i].seriesName + " " + p[i].value + " " + "(" + ((100 * parseFloat(p[i].value)) / parseFloat(_max)).toFixed(2) + "%)";
}
}
return relVal;
}
},
backgroundColor: "#f666",
legend: {
show:false,
data: ['正常','故障','预警','异常'],
icon: "rect",
itemWidth: 10,
   itemHeight: 10,
selectedMode: false,
textStyle: {
color: "#666666",
fontSize: 14
}
},
grid: {
left: "14%",
right: "10%",
bottom: "5%",
top: "20%",
containLabel: true
},
xAxis: [{
type: "value",
show: false,
splitNumber: spNum,
interval: _max / spNum,
max: _max,
axisLabel: {
show: false,
formatter: function(v) {
var _v = (v / _max * 100).toFixed(0);
return _v == 0 ? _v : _v + '%';
}
},
axisLine: {
show: false
},
axisTick: {
show: false
},
splitLine: {
show: false
}
}
],
yAxis: [{
type: "category",
axisLine: {
show: false
},
axisTick: {
show: false
},
axisLabel: {
color: "#333333",
fontSize: 14,
fontWeight: 400,
interval: 0
},
offset: 20,
data: honorXAxisData
},
{
type: "category",
axisLine: {
show: false
},
axisTick: {
show: false
},
axisLabel: {
color: "#fff",
fontSize: 10,
fontWeight: 300,
interval: 0
}
}
],
series: [
{
name: " ",
type: "bar",
label: _label,
barWidth: 12,
stack: "总量",
itemStyle: {
normal: {
color: function(params) {
var num = myColor.length;
return myColor[params.dataIndex % num]
},
}
},
zlevel: 10,
data: honorData4
},
{
name: "1000",
type: "bar",
barGap: "-100%",
barWidth: 12,
itemStyle: {
normal: {
color: '#efefef'
}
},
xAxisIndex: 0,
// yAxisIndex: 1,
data: bjData1,
emphasis: {
itemStyle: {
color: '#efefef'
}
},
zlevel: 5
}
]
}

转载于:https://www.cnblogs.com/hrr666/p/11477208.html

你可能感兴趣的文章
20172327 2017-2018-2 《程序设计与数据结构》第九周学习总结
查看>>
课本一二章
查看>>
在url中传递参数(方法二)
查看>>
我的 Python3.x 的开始-2018.8.3
查看>>
Fiddler 教程
查看>>
[题解]诸侯安置(dp+组合)
查看>>
CentOS6和CentOS7进入单用户模式重置root密码
查看>>
PHP之mb_convert_case使用
查看>>
python + eclipse +pydev
查看>>
zabbix---agent安装
查看>>
mysql主从复制与读写分离
查看>>
内核创建进程的流程
查看>>
python一切皆对象的理解
查看>>
关于getResource和getClassLoader().getResource()
查看>>
你其实没的选择
查看>>
编程菜鸟的日记-初学尝试编程-C++ Primer Plus 第6章编程练习6
查看>>
C#笔试题收集
查看>>
ERROR 1290 (HY000): The MySQL server is running with&nbs
查看>>
我为什么要写博客
查看>>
成绩转换
查看>>