//定义图表对象
var myChart1 = null;
var myChart2 = null;
var myChart3 = null;
var myChart4 = null;
var myChart5 = null;
var myChart6 = null;
var myChart7 = null;
var myChart8 = null;
$(function() {
function load() {
$.ajax({
url: "c1.htm", async: false, dataType: 'json', success: function(result) {
industryBar(result.array);
}
});
$.ajax({
url: "c2.htm", async: false, dataType: 'json', success: function(result) {
changeChart(result.array);
}
});
$.ajax({
url: "c3.htm", async: false, dataType: 'json', success: function(result) {
skillAcquisitionChart(result.array);
}
});
// $.ajax({
// url: "c4.htm", async: false, dataType: 'json', success: function(result) {
// pieChart(result.array);
// }
// });
var currentnum = 0; allnum = 0;
$.ajax({
url: "allnum.htm", async: false, dataType: 'json', success: function(result) {
allnum = result.array[0].allnum;
currentnum = result.array[0].currentnum;
}
});
clocknum(currentnum, 'requiredPeoples');
clocknum(allnum, 'supplyPeoples');
}
load();
setInterval(function() {
load();
}, 10000);
//roseChart();
/* $(".digits").numScroll({
time:5000
});*/
});
/**
* 柱形图
*/
function industryBar(data) {
let xAxisData = data.map(v => v.college);
let yAxisData = data.map(v => v.currentnum);
myChart1 = echarts.init(document.getElementById('industryBar')); // 基于准备好的dom,初始化echarts实例
var option = {
title: {
text: '院系报到数据',
left: 'center',
textStyle: { color: '#fff' },
top: '4%',
},
tooltip: {
trigger: 'axis',
axisPointer: { // 坐标轴指示器,坐标轴触发有效
type: 'line' // 默认为直线,可选为:'line' | 'shadow'
}
},
grid: {
left: '2%',
right: '4%',
top: '12%',
bottom: '3%',
containLabel: true
},
xAxis: [
{
type: 'category',
data: xAxisData,
axisTick: {
alignWithLabel: false
},
axisLabel: { //x轴文字颜色
color: '#fff',
show: true,
formatter: function(value, index) {
return value.split('').join('\n');
}
},
axisLine: { //x轴线的颜色
lineStyle: {
color: ['#fff'],
width: 1,
type: 'solid',
opacity: 0.1
}
}
}
],
yAxis: [
{
type: 'value',
axisLabel: { //y轴文字颜色
color: '#fff'
},
axisLine: { //y轴线的颜色
lineStyle: {
color: ['#fff'],
width: 1,
type: 'solid',
opacity: 1
}
},
splitLine: { //网格样式
show: true,
lineStyle: {
color: 'rgba(255,255,255,0.3)',
width: 1,
type: 'dashed'
}
}
}
],
series: [
{
// name: '直接访问',
type: 'bar',
barWidth: '50%',
itemStyle: {
normal: {
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
offset: 0,
color: '#248ff7'
}, {
offset: 1,
color: '#6851f1'
}]),
barBorderRadius: 11,
}
},
data: yAxisData
}
]
};
myChart1.setOption(option, true); // 使用刚指定的配置项和数据显示图表。
$(document).ready(function() {
myChart1.resize();
})
window.addEventListener("resize", function() {
myChart1.resize();
});
}
var app = {
currentIndex: -1,
};
setInterval(function() {
var dataLen = 15;
// 取消之前高亮的图形
myChart1.dispatchAction({
type: 'downplay',
seriesIndex: 0,
dataIndex: app.currentIndex
});
app.currentIndex = (app.currentIndex + 1) % dataLen;
//console.log(app.currentIndex);
// 高亮当前图形
myChart1.dispatchAction({
type: 'highlight',
seriesIndex: 0,
dataIndex: app.currentIndex,
});
// 显示 tooltip
myChart1.dispatchAction({
type: 'showTip',
seriesIndex: 0,
dataIndex: app.currentIndex
});
}, 1000);
/**
*折线图
*/
function changeChart(data) {
let x = data.map(v => v.name);
let d1 = data.map(v => v.d1);
let d2 = data.map(v => v.d2);
myChart2 = echarts.init(document.getElementById('changeLine'));
var option = {
title: {
text: '报到接种疫苗',
left: 'center',
show:false,
textStyle: { color: '#fff' },
top: '4%',
},
grid: {
left: '2%',
right: '4%',
top: '8%',
bottom: '3%',
containLabel: true
},
legend: {
data: ['已报到', '已接种'],
textStyle: { color: '#fff' },
right: '4%',
top: '3%',
bottom: '5%',
},
xAxis: {
type: 'category',
data: x,
axisLabel: { //x轴文字颜色
color: '#fff',
interval: 0,
// rotate:"45"
},
axisLine: { //x轴线的颜色
lineStyle: {
color: ['#fff'],
width: 1,
type: 'solid',
opacity: 0.1
}
}
},
yAxis: {
type: 'value',
axisLabel: { //x轴文字颜色
color: '#fff'
},
axisLine: { //x轴线的颜色
lineStyle: {
color: ['#fff'],
width: 1,
type: 'solid',
opacity: 0.1
}
},
splitLine: { //网格样式
show: true,
lineStyle: {
color: 'rgba(255,255,255,0.1)',
width: 1,
type: 'dashed'
}
}
},
color: ['#01dee1', "#ed3f35"], //曲线颜色
series: [{
name: '已报到',
type: 'bar',
data: d1,
label: {
show: true
},
itemStyle: {
normal: {
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
offset: 0,
color: '#0090FF'
}, {
offset: 1,
color: '#0090FF'
}]),
barBorderRadius: 11,
}
}
}, {
name: '已接种',
type: 'bar',
data: d2,
label: {
show: true
},
itemStyle: {
normal: {
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
offset: 0,
color: '#ff3300'
}, {
offset: 1,
color: '#ff3333'
}]),
barBorderRadius: 11,
}
}
}]
};
myChart2.setOption(option, true); // 使用刚指定的配置项和数据显示图表。
$(document).ready(function() {
myChart2.resize();
})
window.addEventListener("resize", function() {
myChart2.resize();
});
}
/**
*饼形图
*/
function ageTrendPie() {
myChart3 = echarts.init(document.getElementById('agePie'));
var option = {
title: {
text: '年龄分析',
left: 'center',
textStyle: { color: '#fff' },
top: '4%',
},
tooltip: {
trigger: 'item',
formatter: '{a}
{b}: {c} ({d}%)'
},
grid: {
left: '3%',
right: '4%',
top: '35%',
bottom: '3%'
},
legend: {
orient: 'vertical',
left: 10,
data: ['16岁', '17岁', '18岁', '19岁', '20岁', '21岁以上'],
textStyle: {
color: '#fff'
}
},
series: [
{
name: '年龄占比',
type: 'pie',
radius: ['50%', '70%'],
avoidLabelOverlap: true,
label: {
show: false,
position: 'center'
},
emphasis: {
label: {
show: true,
fontSize: '30',
fontWeight: 'bold'
}
},
labelLine: {
show: false
},
itemStyle: {
normal: {
label: {
show: true,
formatter: '{b} \n ({d}%)'
}
}
},
color: ['#10606b', '#0696ab', '#06a0ab', '#86c9f4', '#4da8ec', '#3a91d2', '#005fa6', '#315f97'],
data: [
{ value: 999, name: '16岁' },
{ value: 2000, name: '17岁' },
{ value: 1548, name: '18岁' },
{ value: 1548, name: '19岁' },
{ value: 1548, name: '20岁' },
{ value: 1548, name: '21岁以上' }
]
}
]
};
myChart3.setOption(option, true); // 使用刚指定的配置项和数据显示图表。
$(document).ready(function() {
myChart3.resize();
})
window.addEventListener("resize", function() {
myChart3.resize();
});
}
/**
*柱形图
*/
function skillAcquisitionChart(cost) {
//var cost = [1679, 78, 60, 34, 70,80,90]//本期比上期(大于1按1处理)
var totalCost = [1679, 1679, 1679, 1679, "1679", "1679", "1679"]//比例综合
var visits = [1679, 1679, 1679, 1679, "1679", "1679", "1679"]//本期占总的百分比*100
var grade = ['招生处', '医务室', '保卫处', '学工部', '组织部', '公寓', '院系办公室'];
var myColor = ['#21BF57', '#56D0E3', '#1089E7', '#F8B448', '#F57474',];
var data = {
grade: grade,
cost: cost,
totalCost: totalCost,
visits: visits
};
var option = {
title: {
top: '4%',
left: 'center',
text: '节点报到数据',
textStyle: {
align: 'center',
color: '#fff'
}
},
grid: {
left: '50',
right: '35',
bottom: '20'
},
xAxis: {
show: false,
},
yAxis: {
type: 'category',
inverse: true,//倒
axisLabel: {
margin: 20,
show: true,
color: '#4DCEF8',
fontSize: 12,
formatter: function(value, index) {
return value.split('').join('\n');
}
},
axisTick: {
show: false,
},
axisLine: {
show: false,
},
data: data.grade
},
series: [{//外层边框
type: 'bar',
barGap: '-65%',
label: {
normal: {
show: true,
position: 'right',
color: '#fff',
fontSize: 14,
formatter:
function(param) {
return data.visits[param.dataIndex];
},
}
},
barWidth: '50%',
itemStyle: {
normal: {
borderColor: '#4DCEF8',
borderWidth: 2,
barBorderRadius: 12,
color: 'rgba(102, 102, 102,0)'
},
},
z: 1,
data: data.totalCost,
// data: da
}, {//柱形图占比
type: 'bar',
barGap: '-85%',
barWidth: '35%',
itemStyle: {
normal: {
barBorderRadius: 14,
color: function(params) {
var num = myColor.length;
return myColor[params.dataIndex % num]
},
}
},
max: 1,
label: {
normal: {
show: true,
position: 'inside',
formatter: '{c}'
}
},
labelLine: {
show: true,
},
z: 2,
data: data.cost,
}]
}
myChart4 = echarts.init(document.getElementById('skillAcquisitionBar'));
myChart4.setOption(option, true);
$(document).ready(function() {
myChart4.resize();
})
window.addEventListener("resize", function() {
myChart4.resize();
});
}
/**
*折线图
*/
function playCounts(echartData) {
let bgColor = "#fff";
let color = [
"#0090FF",
"#36CE9E",
"#FFC005",
"#FF515A",
"#8B5CFF",
"#00CA69"
];
let xAxisData = echartData.map(v => v.name);
// ["1", "2", "3", "4", "5", "6", "7", "8"]
let yAxisData1 = echartData.map(v => v.value1);
// [100, 138, 350, 173, 180, 150, 180, 230]
let yAxisData2 = echartData.map(v => v.value2);
// [233, 233, 200, 180, 199, 233, 210, 180]
let yAxisData3 = [233, 233, 200, 180, 199, 233, 210, 180];
const hexToRgba = (hex, opacity) => {
let rgbaColor = "";
let reg = /^#[\da-f]{6}$/i;
if (reg.test(hex)) {
rgbaColor = `rgba(${parseInt("0x" + hex.slice(1, 3))},${parseInt(
"0x" + hex.slice(3, 5)
)},${parseInt("0x" + hex.slice(5, 7))},${opacity})`;
}
return rgbaColor;
}
/////////////////////
var option = {
title: {
top: '4%',
left: 'center',
text: '本硕博 ',
textStyle: {
align: 'center',
color: '#fff'
}
},
legend: {
right: 10,
top: 10,
textStyle: {
color: "#fff"
}
},
tooltip: {
trigger: "axis",
formatter: function(params) {
let html = '';
params.forEach(v => {
console.log(v)
html += `