饼图
样例一:(中间文字固定显示带提示框)
样例一配置项:
option = {
title: {//标题
text: '会话统计',
x: 20,
y: 20,
textStyle: {
color: '#3C4353',
fontSize: 12
}
},
graphic: [//固定文字或者图标
{
type: 'text',
left: 'center',
top: '48%',
style: {
text: '4545',
textAlign: 'center',
fill: '#3C4353',
fontSize: 40
}
},
{ //图形中间文字
type: 'text',
left: 'center',
top: '55%',
style: {
text: '会话总数',
textAlign: 'center',
fill: '#838A9D',
fontSize: 17
}
}
],
tooltip: {//提示文字
trigger: 'item',
position: 'top',
transitionDuration: 0,
extraCssText: 'box-shadow:0px 1px 20px 0px rgba(0,0,0,0.1);width:140px;',
backgroundColor: 'white',
formatter: '<span style="font-size: 12px;">{b}: {c} ({d}%)</span>',
borderColor: '#333',
textStyle: {
color: '#333333'
}
},
legend: {//展示选项
bottom: 30,
left: 'center',
icon: 'circle',
itemWidth: 8,
itemHeight: 8,
itemTop: 10,
data: ['丢包会话', '未丢包会话']
},
series: [//展示图选择(饼图、折线)
{
name: '访问来源',
type: 'pie',
radius: ['55%', '45%'],
hoverOffset: 1,
avoidLabelOverlap: false,
label: {
show: false,
position: 'center'
/*formatter: function(data) {富文本展示hover中心文字变化
let a = data.value;
return '{a|' + a + '}' + '{b| 会话总数}';
},
rich: {
a: {
lineHeight: 25,
color: '#3C4353',
fontSize: 30
},
b: {
lineHeight: 25,
color: '#838A9D',
fontSize: 10
}
},*/
},
center: ['50%', '50%'],//环形大小
labelLine: {
show: false
},
itemStyle: {//item得的样式定义
normal: {
color: function (params) {
//自定义颜色
let colorList = [
'#F7B500', '#E2E4E8'
];
return colorList[params.dataIndex];
}
}
},
data: [
{value: 1, name: '丢包会话'},
{value: 2, name: '未丢包会话'}
]
}
]
};
折线图
样例一:
样例一配置项:
option: {
title: {//标题
text: '丢包率TOP5',
x: 20,
y: 20,
textStyle: {
color: '#333333',
fontSize: 12
}
},
tooltip: {//提示框
trigger: 'axis',
position: 'left',
extraCssText: 'box-shadow:0px 1px 20px 0px rgba(0,0,0,0.1);',
backgroundColor: 'white',
formatter: function (params) { //富文本函数用于提示框
let iconPath = [
'./static/images/session-detection/circle_red.png',
'./static/images/session-detection/circle_orange.png',
'./static/images/session-detection/circle_yellow.png',
'./static/images/session-detection/circle_bule.png',
'./static/images/session-detection/circle_green.png'
];
let str = '';
for (let i = 0; i < params.length; i++) {
if (i === 0) {
str += '<div style="margin-top: 3px;"></div>';
}
str += '<image width="10px" height="10px" style="margin-left: 10px" src="' + iconPath[i] + '"/>';
str += '<span style="font-size: 12px; margin-left: 10px;">' + params[i].seriesName + '</span>';
str += '<span style="font-size: 12px; margin-left: 10px;">' + params[i].value + '%</span><br/>';
}
return str;
},
borderColor: '#333',
axisPointer: { //坐标轴指示器,坐标轴触发有效,
type: 'line', //默认为line,line直线,cross十字准星,shadow阴影
lineStyle: {
color: '#6493F4'
}
},
textStyle: {
color: '#333333'
}
},
legend: {
y: 45,
right: '3%',
itemWidth: 8,
itemHeight: 8,
data: [
{
name: 'line1',
icon: 'image://./static/images/session-detection/circle_red.png'
},
{
name: 'line2',
icon: 'image://./static/images/session-detection/circle_orange.png'
},
{
name: 'line3',
icon: 'image://./static/images/session-detection/circle_yellow.png'
}
]
},
grid: {//图表位置
left: '3%',
right: '3%',
y: 80,
bottom: '3%',
containLabel: true
},
xAxis: {
type: 'category',
boundaryGap: false,//x轴两边留白策略
data: ['', '12:10:00', '12:11:00', '12:30:00', '13:00:00', '14:00:00', '15:00:00'],
// y轴的字体样式
axisLabel: {
show: true,
textStyle: {
color: '#60697B'
}
},
axisLine: { //x轴颜色和宽度
lineStyle: {
color: '#E2E5EB'
}
}
},
yAxis: {
data: [0, 20, 40, 60, 80, 100],
type: 'value',//若y轴为离散形且为柱形图 柱形将从y轴开始横展示
max: 100,
min: 0,
name: '百分比(%)',
nameTextStyle: {
padding: [0, 10, 0, 0],
color: '#60697B'
},
splitLine: { //网格线
lineStyle: {
type: 'dashed', //设置网格线类型 dotted:虚线 solid:实线
width: 0.5
},
show: true //隐藏或显示
},
axisLabel: {
show: true,
textStyle: {
color: '#60697B'
}
},
axisLine: {
lineStyle: {//x轴颜色和宽度
color: '#E2E5EB',
width: 2
}
}
},
series: [
{
name: 'line1',
type: 'line',
data: [10, 45, 69, 89, 56, 36, 12],
symbol: 'none',
itemStyle: {
normal: {
color: '#FA3535'
}
}
},
{
name: 'line2',
type: 'line',
data: [45, 69, 89, 56, 36, 12,10],
symbol: 'none',//折点
itemStyle: {
normal: {
color: '#FF7F3F'
}
}
},
{
name: 'line3',
type: 'line',
data: [69, 89, 56, 36, 12, 20, 98],
symbol: 'none',
itemStyle: {
normal: {
color: '#F7B500'
}
}
}
]
}
柱形图
样例一:
样例代码:
option: {
title: {//标题
text: '单会话码率',
x: 20,
y: 20,
textStyle: {
color: '#333333',
fontSize: 12
}
},
backgroundColor: 'white',
legend: { //选例
data: [
{
name: '丢包率',
icon: 'image://./static/images/session-detection/circle_bule.png'
},
{name: '上行码率'},
{name: '下行码率'}
],
icon: 'circle',
itemWidth: 8,//选例图表大小
itemHeight: 8,
borderColor: '#f58f23',
right: '40%',
y: 45
},
tooltip: {//提示框
trigger: 'axis',
position: 'left',
extraCssText: 'box-shadow:0px 1px 20px 0px rgba(0,0,0,0.1);',//提示框阴影大小
backgroundColor: 'white',
borderColor: '#333',
formatter: function (params) { //富文本格式化函数
let iconPath = [
'./static/images/session-detection/circle_bule.png',
'./static/images/session-detection/circle_blues.png',
'./static/images/session-detection/circle_yellows.png'
];
let str = '';
for (let i = 0; i < params.length; i++) {
if (i === 0) {
str += '<div style="margin-top: 3px;width: 100%"></div>';
}
str += '<image width="10px" height="10px" style="margin-left: 10px" src="' + iconPath[i] + '"/>';
str += '<span style="font-size: 12px; margin-left: 10px;">' + params[i].seriesName + '</span>';
if (i === 0) {
str += '<span style="font-size: 12px; margin-left: 10px;">' + params[i].value + '%</span><br/>';
} else if (i === 2) {
str += '<span style="font-size: 12px; margin-left: 10px;">' + params[i].value * -1 + 'Mbps</span><br/>';
} else if (i === 1){
str += '<span style="font-size: 12px; margin-left: 10px;">' + params[i].value + 'Mbps</span><br/>';
}
}
return str;
},
textStyle: {
color: '#333333'
},
axisPointer: { //坐标轴指示器
type: 'line', //默认为line
lineStyle: {
color: '#6493F4'
},
z: 0 //相当于z-index
}
},
xAxis: {
data: ['12:10:01', '12:10:02', '12:10:03', '12:10:04', '12:10:05', '12:10:06', '12:10:07'],
splitLine: {show: false},
axisLabel: {
show: true,
textStyle: {
color: '#60697B'
}
},
axisLine: { //x轴颜色和宽度
onZero: true,
lineStyle: {
color: '#E2E5EB'
}
},
splitArea: {show: false}
},
yAxis: [//双y轴则为数组
{
/*inverse: true,*/
max: 100,
min: 0,
name: '丢包率(%)',
nameTextStyle: {
align: 'center',
padding: [0, 0, 0, 25],
color: '#60697B'
},
splitLine: {
show: false
},
axisLabel: {
show: true,
textStyle: {
color: '#60697B'
}
},
axisLine: {
lineStyle: {//x轴颜色和宽度
color: '#E2E5EB',
width: 1
}
}
},
{
/*inverse: true,*/
/*type: 'category',*///用于固定数据
max: 20,
min: -20,
name: '码率(Mbps)',
nameTextStyle: {
align: 'center',
padding: [0, 0, 0, -25],
color: '#60697B'
},
splitArea: {show: false},
axisLine: {
lineStyle: { //x轴颜色和宽度
color: '#E2E5EB',
width: 1
}
},
axisLabel: {
show: true,
textStyle: {
color: '#60697B'
}
},
splitLine: { //网格线
lineStyle: {
type: 'dashed', //设置网格线类型 dotted:虚线 solid:实线
width: 0.5
},
show: true //隐藏或显示
}
}
],
grid: { //图表位置
y: 80,
x2: 50,
left: 60
},
series: [
{ //折线
name: '丢包率',
type: 'line',
smooth: true,
yAxisIndex: 0,
symbolSize: 5,
itemStyle: {
normal: {
color: '#8cd5c2', //改变折线点的颜色
borderColor: '#4980F2',
lineStyle: {
color: '#4980F2' //改变折线颜色
}
}
},
areaStyle: { //渐变背景色的设置
normal: {
color: {
type: 'linear',
x: 0,
y: 0,
x2: 0,
y2: 1,
colorStops: [{
offset: 0, color: '#6493F4' // 0% 处的颜色
}, {
offset: 1, color: '#FFFFFF' // 100% 处的颜色
}],
global: false // 缺省为 false
}
}
},
data: [10, 56, 89, 63, 33, 45, 68]
},
{
name: '上行码率',
type: 'bar',
stack: 'one', //同一名字则为正负柱形图
emphasis: '',
yAxisIndex: 1,
barWidth: 10,
data: [4, 6, 8, 12, 14, 16, 8],
itemStyle: {
normal: {
color: '#4980F2',
barBorderRadius: [10, 10, 10, 10]
}
}
},
{
name: '下行码率',
type: 'bar',
stack: 'one',
yAxisIndex: 1,
emphasis: '',
barWidth: 10,
itemStyle: {
normal: {
color: '#F7B500',
barBorderRadius: [10, 10, 10, 10]
}
},
data: [-4, -6, -8, -12, -14, -16, -8]
}
]
}
样例二:(此图同样为正负柱形图只不过一部分设置为白色了 )y为离散值可实现颠倒
图例代码:
option: {
title: {//标题
x: -5,
text: '模块一AAa(时延: 30MS)',
textStyle: {
color: '#333333',
fontSize: 10
}
},
grid: {//图表位置
y: 20,
x: 20,
width: '100%',
right: '4%',
bottom: '3%',
containLabel: true
},
dataZoom: [//滚动条(为时间轴的时候用)
{
type: 'slider',
bottom: 0,
show: true,
xAxisIndex: [0],
start: 1,
end: 50
}
],
xAxis: {
type: 'value',
splitNumber: 0,
axisLabel: {
show: true,
textStyle: {
color: '#60697B',
fontSize: 10
}
},
axisTick: {//坐标轴刻度线
show: false
},
splitLine: { //网格线
show: false //隐藏或显示
},
axisLine: { //x轴颜色和宽度
lineStyle: {
color: '#4980F2',
width: 3
}
}
},
yAxis: {
type: 'category',
data: ['A', 'B', 'C', 'D', 'E'],
axisLabel: {
show: false,
textStyle: {
color: '#60697B',
fontSize: 8
}
},
splitLine: { //网格线
lineStyle: {
type: 'dashed', //设置网格线类型 dotted:虚线 solid:实线
width: 0.5
},
show: true //隐藏或显示
},
axisLine: { //x轴颜色和宽度
lineStyle: {
color: '#fff'
}
}
},
series: [
{
name: 'chart1',
type: 'bar',
stack: '总量',
itemStyle: {
color: 'white'
},
label: {
show: true,
fontSize: 10,
lineHeight: 1,
position: ['100%', '-100%'],
color: '#4980F2',
formatter: function (params) {
return params.name;
}
},
data: [100, 80, 60, 40, 20]
},
{
name: 'chart1s',
type: 'bar',
stack: '总量',
itemStyle: {
normal: {
color: 'yellow',
borderColor: 'yellow'
}
},
zlevel: 3,
barWidth: 10,
data: [100, 80, 60, 40, 20]
}
]
},
后续将不断更新图例或者其他模板。