O、预览图
实现图例切换效果的重点:
(1)图例设置单选: selectedMode: 'single'
(2)图例中 data: ['组织','课程','培训','专家']
的每个元素需与option.series
数组中的每一个name属性值相对应即可切换。
(3)option.series
数组中的每一个name属性值设置为空串''
(即不能匹配),故这样的数据(series)即公共系列,每个页签中都会显示(详见 图2、图3代码)。
一、图1代码
/*
//图标
var uploadedDataURL = "/asset/get/s/data-1559121268278-ozjd-lXoz.png";
var uploadedDataURL = "/asset/get/s/data-1559121263841-UC5w7mTJ9.png";
var uploadedDataURL = "/asset/get/s/data-1559121259198-sxyPSimU9.png";
var uploadedDataURL = "/asset/get/s/data-1559121254241-xj5JAIBzC.png";
var uploadedDataURL = "/asset/get/s/data-1559121249274-QxHDAdQGy.png";
*/
var sportsIcon = {
'a':'/asset/get/s/data-1559121268278-ozjd-lXoz.png',
'b':'/asset/get/s/data-1559121263841-UC5w7mTJ9.png',
'c':'/asset/get/s/data-1559121259198-sxyPSimU9.png',
'd':'/asset/get/s/data-1559121254241-xj5JAIBzC.png',
'e':'/asset/get/s/data-1559121249274-QxHDAdQGy.png',
};
//var colorList=['#6782B8', '#BEC7F2', '#CCE9BD', '#C1E0DE', '#B6EAFF', "rgba(250,250,250,0.5)"];
//满意度类型
var type=${[table1.B2,table1.B3,table1.B4,table1.B5,table1.B6]};
// (1)组织系列数据
var count1=${[table1.C2,table1.C3,table1.C4,table1.C5,table1.C6]};//数量
var percentage1=${[table1.D2,table1.D3,table1.D4,table1.D5,table1.D6]};//占比
var sum1=100;//总数
var data1=[];
for(var i=0; i<type.length; i++){
var node = {
value:count1[i],
name:type[i],
percentage:percentage1[i]
};
data1.push(node);
}
// (2)课程系列数据
var count2=${[table3.C2,table3.C3,table3.C4,table3.C5,table3.C6]};//数量
var percentage2=${[table3.D2,table3.D3,table3.D4,table3.D5,table3.D6]};//占比
var sum2=200;//总数
var data2=[];
for(var i=0; i<type.length; i++){
var node = {
value:count2[i],
name:type[i],
percentage:percentage2[i]
};
data2.push(node);
}
// (3)培训系列数据
var count3=${[table4.C2,table4.C3,table4.C4,table4.C5,table4.C6]};//数量
var percentage3=${[table4.D2,table4.D3,table4.D4,table4.D5,table4.D6]};//占比
var sum3=300;//总数
var data3=[];
for(var i=0; i<type.length; i++){
var node = {
value:count3[i],
name:type[i],
percentage:percentage3[i]
};
data3.push(node);
}
// (4)专家系列数据
var count4=${[table5.C2,table5.C3,table5.C4,table5.C5,table5.C6]};//数量
var percentage4=${[table5.D2,table5.D3,table5.D4,table5.D5,table5.D6]};//占比
var sum4=400;//总数
var data4=[];
for(var i=0; i<type.length; i++){
var node = {
value:count4[i],
name:type[i],
percentage:percentage4[i]
};
data4.push(node);
}
//转数据点名称和数据点值的内容
var data11 = option.series[0].data;
data1.forEach(function(d){
var name = d.name;
for (var i = 0,len=data11.length;i<len;i++) {
var d1 = data11[i];
var _name = d1.name;
if (_name && _name.replace('\\n', '\n') == name) {
d.link = d1.link;
break;
}
}
});
var data22 = option.series[1].data;
data2.forEach(function(d){
var name = d.name;
for (var i = 0,len=data22.length;i<len;i++) {
var d1 = data22[i];
var _name = d1.name;
if (_name && _name.replace('\\n', '\n') == name) {
d.link = d1.link;
break;
}
}
});
var data33 = option.series[2].data;
data3.forEach(function(d){
var name = d.name;
for (var i = 0,len=data33.length;i<len;i++) {
var d1 = data33[i];
var _name = d1.name;
if (_name && _name.replace('\\n', '\n') == name) {
d.link = d1.link;
break;
}
}
});
var data44 = option.series[3].data;
data4.forEach(function(d){
var name = d.name;
for (var i = 0,len=data44.length;i<len;i++) {
var d1 = data44[i];
var _name = d1.name;
if (_name && _name.replace('\\n', '\n') == name) {
d.link = d1.link;
break;
}
}
});
//颜色
var normalColors = {
color: function (params) {
var colorList = [
['#c8e2c7', '#7baf8c'],['#accfd2', '#69a4b4'],
['#b6d9f6', '#4f9be5'],['#b1beee', '#647fcb'],
['#e5defa', '#9b9bee'],['#96acd8', '#2d4893'],
['#adc6e3', '#5f85d7']
];
var index= params.dataIndex % colorList.length;
return new echarts.graphic.LinearGradient(0, 0, 0, 1,[{offset: 0,color: colorList[index][0] },{ offset: 1,color: colorList[index][1]}]);
}
};
option.grid= {
bottom: 150,
left: 0,
right: '10%'
};
option.xAxis= [{
//type: "category",
axisLine: {
lineStyle: {
show: false
},
show: false
},
axisLabel: {
show: false,
}
}];
option.legend= {
icon: "roundRect", //图例形状( circle,rect,line,roundRect,triangle,diamond,pin,arrow,none)
//图例自定义图片形状
//icon : 'image://../../images/hsyb/water.png' // image:// 后跟图片路径
icon : 'image:///meta/QJC_V3/analyses/ZHFX/BI_GYSHX/images/icon_2.png',
// top: "center",
orient: "vartical",
x: 'left', // 'center' | 'left' | {number}, x轴设置图例位置水平方向上的上下左右
y: '15', // 'center' | 'bottom' | {number} y轴设置图例位置垂直方向的上下左右
//left: "3%",
itemWidth: 14,
itemHeight: 14,
itemGap :10,// 设置间距
show:true,
selectedMode: 'single',
data: ['组织','课程','培训','专家'],
inactiveColor: '#8F9193',//图例默认颜色868686
textStyle: { //图例选中样式
color: '#526FC1',//0068DF
padding: [5, 7, 5, 7],
borderColor:'#F2F2F7',
borderRadius:3,
backgroundColor: 'rgba(208,218,233,1)',
borderWidth: 1,
fontSize: 14,
fontWeight:550
}
};
option.series= [
{
name:'组织',
type: 'pie',
radius: ['30%', '51%'],
center: ['50%', '50%'],
itemStyle: {
normal: normalColors
},
labelLine:{
normal:{
length:25
}
},
label:{
normal:{
textStyle:{
// color:'black' //字体颜色
fontSize: '13',
fontWeight: 'normal', //bolder
fontFamily: 'Microsoft YaHei',
},
formatter: function(params){
return params.name+':'+count1[params.dataIndex];
//return params.name+':'+count1[params.dataIndex]+'('+percentage1[params.dataIndex]+')';
}
}
},
data: data1
},
{
name:'课程',
type: 'pie',
radius: ['30%', '51%'],
center: ['50%', '50%'],
itemStyle: {
normal: normalColors
},
labelLine:{
normal:{
length:25
}
},
label:{
normal:{
textStyle:{
// color:'black' //字体颜色
fontSize: '13',
fontWeight: 'normal', //bolder
fontFamily: 'Microsoft YaHei',
},
formatter: function(params){
return params.name+':'+count2[params.dataIndex]+'('+percentage2[params.dataIndex]+')';
}
}
},
data: data2
},
{
name:'培训',
type: 'pie',
radius: ['30%', '51%'],
center: ['50%', '50%'],
itemStyle: {
normal: normalColors
},
labelLine:{
normal:{
length:25
}
},
label:{
normal:{
textStyle:{
// color:'black' //字体颜色
fontSize: '13',
fontWeight: 'normal', //bolder
fontFamily: 'Microsoft YaHei',
},
formatter: function(params){
return params.name+':'+count3[params.dataIndex]+'('+percentage3[params.dataIndex]+')';
}
}
},
data: data3
},
{
name:'专家',
type: 'pie',
radius: ['30%', '51%'],
center: ['50%', '50%'],
itemStyle: {
normal: normalColors
},
labelLine:{
normal:{
length:25
}
},
label:{
normal:{
textStyle:{
// color:'black' //字体颜色
fontSize: '13',
fontWeight: 'normal', //bolder
fontFamily: 'Microsoft YaHei',
},
formatter: function(params){
return params.name+':'+count4[params.dataIndex]+'('+percentage4[params.dataIndex]+')';
}
}
},
data: data4
},
// 边框的设置
{
radius: ['47%', '51%'],
center: ['50%', '50%'],
type: 'pie',
label: {
normal: {
show: false
},
emphasis: {
show: false
}
},
labelLine: {
normal: {
show: false
},
emphasis: {
show: false
}
},
animation: false,
tooltip: {
show: false
},
itemStyle: {
normal: {
color:'rgba(250,250,250,0.5)'
}
},
data: [{
value: 1,
}],
}
];
/*
option.title={
text:100,
subtext: '总数',
x: 'center',
y: 'center',
textStyle: {
fontSize:18,
fontWeight:'normal',
color: ['#333']
},
subtextStyle: {
color: '#666',
fontSize: 13
},
};
*/
option.tooltip = {
show: true,
trigger: 'item',
formatter: function(params) {
return params.name+"<br>数量:"+params.value
+"<br>占比:"+params.data.percentage;
//return params.name+"<br>数量:"+params.value +"<br>占比:"+Math.round(params.value*1.0/sum * 10000) / 100 + '%';
},
textStyle : {
color : '#FFFFFF'
},
axisPointer : {
type : 'shadow'
}
};
二、图2代码
//类型
var type=${[table1.B2,table1.B3,table1.B4,table1.B5,table1.B6,
table1.B7,table1.B8,table1.B9,table1.B10,table1.B11]};
// (1)专业领域覆盖面统计数据
var count1=${[table1.C2,table1.C3,table1.C4,table1.C5,table1.C6,
table1.C7,table1.C8,table1.C9,table1.C10,table1.C11]};//数量
var percentage1=${[table1.D2,table1.D3,table1.D4,table1.D5,table1.D6,
table1.D7,table1.D8,table1.D9,table1.D10,table1.D11]};//占比
var sum1=${table1.B12};//总数
var data1=[];
for(var i=0; i<type.length; i++){
var node = {
name:type[i],
value:count1[i],
percentage:percentage1[i]
};
data1.push(node);
}
// (2)供应商覆盖面统计数据
var count2=${[table4.C2,table4.C3,table4.C4,table4.C5,table4.C6,
table4.C7,table4.C8,table4.C9,table4.C10,table4.C11]};//数量
var percentage2=${[table4.D2,table4.D3,table4.D4,table4.D5,table4.D6,
table4.D7,table4.D8,table4.D9,table4.D10,table4.D11]};//占比
var sum2=${table4.B12};//总数
var data2=[];
for(var i=0; i<type.length; i++){
var node = {
name:type[i],
value:count2[i],
percentage:percentage2[i]
};
data2.push(node);
}
//转数据点名称和数据点值的内容
var data11 = option.series[0].data;
data1.forEach(function(d){
var name = d.name;
for (var i = 0,len=data11.length;i<len;i++) {
var d1 = data11[i];
var _name = d1.name;
if (_name && _name.replace('\\n', '\n') == name) {
d.link = d1.link;
break;
}
}
});
//转数据点名称和数据点值的内容
var data22 = option.series[1].data;
data2.forEach(function(d){
var name = d.name;
for (var i = 0,len=data22.length;i<len;i++) {
var d1 = data22[i];
var _name = d1.name;
if (_name && _name.replace('\\n', '\n') == name) {
d.link = d1.link;
break;
}
}
});
var sportsIcon = {
'a':'/asset/get/s/data-1559121268278-ozjd-lXoz.png',
'b':'/asset/get/s/data-1559121263841-UC5w7mTJ9.png',
'c':'/asset/get/s/data-1559121259198-sxyPSimU9.png',
'd':'/asset/get/s/data-1559121254241-xj5JAIBzC.png',
'e':'/asset/get/s/data-1559121249274-QxHDAdQGy.png',
};
var normalColors = {
color: function (params) {
var colorList = [
['#c8e2c7', '#7baf8c'],['#accfd2', '#69a4b4'],
['#b6d9f6', '#4f9be5'],['#b1beee', '#647fcb'],
['#e5defa', '#9b9bee'],['#96acd8', '#2d4893'],
['#adc6e3', '#5f85d7']
];
var index= params.dataIndex % colorList.length;
return new echarts.graphic.LinearGradient(0, 0, 0, 1,[{offset: 0,color: colorList[index][0] },{ offset: 1,color: colorList[index][1]}]);
}
};
option.grid= {
bottom: 150,
left: 0,
right: '10%'
};
option.xAxis= [{
//type: "category",
axisLine: {
lineStyle: {
show: false
},
show: false
},
axisLabel: {
show: false,
}
}];
option.legend= {
icon: "roundRect", //图例形状( circle,rect,line,roundRect,triangle,diamond,pin,arrow,none)
//icon : 'image://../../images/hsyb/water.png' // image:// 后跟图片路径 //图例自定义图片形状
icon : 'image://../../images/hsyb/water.png',//无该图片,目的是让图例的左侧图示隐藏
orient: "vartical",
x: 'left', // 'center' | 'left' | {number}, x轴设置图例位置水平方向上的上下左右
y: '15', // 'center' | 'bottom' | {number} y轴设置图例位置垂直方向的上下左右
itemWidth: 14,
itemHeight: 14,
itemGap :10,// 设置间距
show:true,
selectedMode: 'single',
inactiveColor: '#8F9193',//图例默认颜色868686
data: [
{
name:'专业领域',
textStyle: { //图例选中样式
color: '#526FC1',//0068DF
padding: [7, 7, 5, 7],
borderColor:'#F2F2F7',
borderRadius:3,
backgroundColor: 'rgba(208,218,233,1)',
borderWidth: 1,
fontSize: 14,
fontWeight:550
}
},{
name:'供应商',
textStyle: { //图例选中样式
color: '#526FC1',//0068DF
padding: [7, 20, 5, 7],
borderColor:'#F2F2F7',
borderRadius:3,
backgroundColor: 'rgba(208,218,233,1)',
borderWidth: 1,
fontSize: 14,
fontWeight:550
}
}]
};
option.series= [
{
name:'专业领域',
type: 'pie',
radius: ['30%', '51%'],
center: ['50%', '50%'],
itemStyle: {
normal: normalColors
},
labelLine:{
normal:{
length:25
}
},
label:{
normal:{
textStyle:{
// color:'black' //字体颜色
fontSize: '13',
fontWeight: 'normal', //bolder
fontFamily: 'Microsoft YaHei',
},
formatter: function(params){
return params.name+':'+count1[params.dataIndex];
//return '{a|}\n{nameStyle|'+params.name+':}'+'{rate|已覆盖:'+percentage1[params.dataIndex]+'}';
},
}
},
data: data1
},
{
name:'供应商',
type: 'pie',
radius: ['30%', '51%'],
center: ['50%', '50%'],
itemStyle: {
normal: normalColors
},
labelLine:{
normal:{
length:25
}
},
label:{
normal:{
textStyle:{
// color:'black' //字体颜色
fontSize: '13',
fontWeight: 'normal', //bolder
fontFamily: 'Microsoft YaHei',
},
formatter: function(params){
return params.name+':'+count2[params.dataIndex];
//return '{a|}\n{nameStyle|'+params.name+':}'+'{rate|已覆盖:'+percentage1[params.dataIndex]+'}';
},
}
},
data: data2
},
// 边框的设置
{
radius: ['47%', '51%'],
center: ['50%', '50%'],
type: 'pie',
label: {
normal: {
show: false
},
emphasis: {
show: false
}
},
labelLine: {
normal: {
show: false
},
emphasis: {
show: false
}
},
animation: false,
tooltip: {
show: false
},
itemStyle: {
normal: {
color:'rgba(250,250,250,0.5)'
}
},
data: [{
value: 1,
}],
}
];
/*
option.title={
text: '100',
subtext: '总数',
x: 'center',
y: 'center',
textStyle: {
fontSize:18,
fontWeight:'normal',
color: ['#333']
},
subtextStyle: {
color: '#666',
fontSize: 13
},
};
*/
option.tooltip = {
show: true,
trigger: 'item',
formatter: function(params) {
return params.name+"<br>数量:"+params.value
+"<br>占比:"+params.data.percentage;
//return params.name+"<br>数量:"+params.value +"<br>占比:"+Math.round(params.value*1.0/sum * 10000) / 100 + '%';
},
textStyle : {
color : '#FFFFFF'
},
axisPointer : {
type : 'shadow'
}
};
三、图3代码
//类型
var type=${[table1.B2,table1.B3,table1.B4,table1.B5,table1.B6,table1.B7,table1.B8,table1.B9,table1.B10,
table1.B11,table1.B12,table1.B13,table1.B14,table1.B15,table1.B16,table1.B17,table1.B18,table1.B19]};
// (1)分类培训统计数据
var count1=${[table1.C2,table1.C3,table1.C4,table1.C5,table1.C6,table1.C7,table1.C8,table1.C9,table1.C10,
table1.C11,table1.C12,table1.C13,table1.C14,table1.C15,table1.C16,table1.C17,table1.C18,table1.C19]};//数量
var percentage1=${[table1.D2,table1.D3,table1.D4,table1.D5,table1.D6,table1.D7,table1.D8,table1.D9,table1.D10,
table1.D11,table1.D12,table1.D13,table1.D14,table1.D15,table1.D16,table1.D17,table1.D18,table1.D19]};//占比
var sum1=100;//总数
var data1=[];
for(var i=0; i<type.length; i++){
var node = {
name:type[i],
value:count1[i],
percentage:percentage1[i]
};
data1.push(node);
}
// (2)分类供应商统计数据
var count2=${[table2.C2,table2.C3,table2.C4,table2.C5,table2.C6,table2.C7,table2.C8,table2.C9,table2.C10,table2.C11,table2.C12,table2.C13,table2.C14,table2.C15,table2.C16,table2.C17,table2.C18,table2.C19]};//数量
var percentage2=${[table2.D2,table2.D3,table2.D4,table2.D5,table2.D6,table2.D7,table2.D8,table2.D9,table2.D10,table2.D11,table2.D12,table2.D13,table2.D14,table2.D15,table2.D16,table2.D17,table2.D18,table2.D19]};//占比
var sum2=100;//总数
var data2=[];
for(var i=0; i<type.length; i++){
var node = {
name:type[i],
value:count2[i],
percentage:percentage2[i]
};
data2.push(node);
}
// (3)分类课程统计数据
var count3=${[table3.C2,table3.C3,table3.C4,table3.C5,table3.C6,table3.C7,table3.C8,table3.C9,table3.C10,table3.C11,table3.C12,table3.C13,table3.C14,table3.C15,table3.C16,table3.C17,table3.C18,table3.C19]};//数量
var percentage3=${[table3.D2,table3.D3,table3.D4,table3.D5,table3.D6,table3.D7,table3.D8,table3.D9,table3.D10,table3.D11,table3.D12,table3.D13,table3.D14,table3.D15,table3.D16,table3.D17,table3.D18,table3.D19]};//占比
var sum3=100;//总数
var data3=[];
for(var i=0; i<type.length; i++){
var node = {
name:type[i],
value:count3[i],
percentage:percentage3[i]
};
data3.push(node);
}
//转数据点名称和数据点值的内容
var data11 = option.series[0].data;
data1.forEach(function(d){
var name = d.name;
for (var i = 0,len=data11.length;i<len;i++) {
var d1 = data11[i];
var _name = d1.name;
if (_name && _name.replace('\\n', '\n') == name) {
d.link = d1.link;
break;
}
}
});
//转数据点名称和数据点值的内容
var data22 = option.series[1].data;
data2.forEach(function(d){
var name = d.name;
for (var i = 0,len=data22.length;i<len;i++) {
var d1 = data22[i];
var _name = d1.name;
if (_name && _name.replace('\\n', '\n') == name) {
d.link = d1.link;
break;
}
}
});
//转数据点名称和数据点值的内容
var data33 = option.series[2].data;
data3.forEach(function(d){
var name = d.name;
for (var i = 0,len=data33.length;i<len;i++) {
var d1 = data33[i];
var _name = d1.name;
if (_name && _name.replace('\\n', '\n') == name) {
d.link = d1.link;
break;
}
}
});
//颜色
var normalColors = {
color: function (params) {
var colorList = [
['#c8e2c7', '#7baf8c'],['#accfd2', '#69a4b4'],
['#b6d9f6', '#4f9be5'],['#b1beee', '#647fcb'],
['#e5defa', '#9b9bee'],['#96acd8', '#2d4893'],
['#adc6e3', '#5f85d7']
];
var index= params.dataIndex % colorList.length;
return new echarts.graphic.LinearGradient(0, 0, 0, 1,[{offset: 0,color: colorList[index][0] },{ offset: 1,color: colorList[index][1]}]);
}
};
option.backgroundColor='rgba(0,0,0,0)';
option.grid= {
"top": "15%",
"left": "15%",
"bottom": "10%",
"right": "10%",
"containLabel": true
};
option.xAxis= [{
data:type,
type: "category",
//main0: ["累计", "当月"],
axisTick: {
alignWithLabel: true
},
nameTextStyle: {
color: "black"
},
axisLine: {
lineStyle: {
color: "#82b0ec",
show: true
}
},
axisLabel: {
textStyle: {
color: "black"
},
formatter:function(value){
var newStr = "";
if(value != null && value.length>0){
for(var i=0; i<value.length; i+=2) {
if(i%2 == 0) {
newStr += value.substr(i,2)+'\n';
}
}
}
return newStr;
}
}
}];
option.legend= {
icon: "roundRect", //图例形状( circle,rect,line,roundRect,triangle,diamond,pin,arrow,none)
icon : 'image://../../images/hsyb/water.png',
show: true,
orient: "vartical",
x: 'left', // 'center' | 'left' | {number}, x轴设置图例位置水平方向上的上下左右
y: '15', // 'center' | 'bottom' | {number} y轴设置图例位置垂直方向的上下左右
//left: "3%",
itemWidth: 14,
itemHeight: 14,
itemGap :10,// 设置间距
selectedMode: 'single',
inactiveColor: '#8F9193',//图例默认颜色868686
data: [
{
name:'分类培训统计',
textStyle: { //图例选中样式
color: '#526FC1',//0068DF
padding: [7, 20, 5, 7],
borderColor:'#F2F2F7',
borderRadius:3,
backgroundColor: 'rgba(208,218,233,1)',
borderWidth: 1,
fontSize: 14,
fontWeight:550
}
},
{
name:'分类供应商统计',
textStyle: { //图例选中样式
color: '#526FC1',//0068DF
padding: [7, 7, 5, 7],
borderColor:'#F2F2F7',
borderRadius:3,
backgroundColor: 'rgba(208,218,233,1)',
borderWidth: 1,
fontSize: 14,
fontWeight:550
}
},
{
name:'分类课程统计',
textStyle: { //图例选中样式
color: '#526FC1',//0068DF
padding: [7, 20, 5, 7],
borderColor:'#F2F2F7',
borderRadius:3,
backgroundColor: 'rgba(208,218,233,1)',
borderWidth: 1,
fontSize: 14,
fontWeight:550
}
}
]
};
option.series= [
{
name: "分类培训统计",
type: 'bar',//pictorialBar
itemStyle: {
normal: normalColors
},
//silent: true,
barWidth: "20",
label: {
normal: {
show: true,
position: "top",
formatter: function(params){
return params.value;//[params.dataIndex]
}
}
},
data: data1
},
{
name: "分类供应商统计",
itemStyle: {
normal: normalColors
},
//silent: true,
barWidth: "20",
type: 'bar',//pictorialBar
label: {
normal: {
show: true,
position: "top",
formatter: function(params){
return params.value;//[params.dataIndex]
}
}
},
data: data2
},
{
name: "分类课程统计",
itemStyle: {
normal: normalColors
},
//silent: true,
barWidth: "20",
type: 'bar',//pictorialBar
label: {
normal: {
show: true,
position: "top",
formatter: function(params){
return params.value;//[params.dataIndex]
}
}
},
data: data3
}
];
option.tooltip = {
show: true,
trigger: 'item',
formatter: function(params) {
return params.name+"<br>数量:"+params.value
+"<br>占比:"+params.data.percentage;
//return params.name+"<br>数量:"+params.value +"<br>占比:"+Math.round(params.value*1.0/sum * 10000) / 100 + '%';
},
textStyle : {
color : '#FFFFFF'
},
axisPointer : {
type : 'shadow'
}
};