import * as echarts from 'echarts'
const iuCharts = {
drawBar:function(chart,params){
var color = ['#4379EE','#FEC53D','#65789B','#F6BD16'];
let series = params.yData.map((m,i)=>{
let obj = {
name: m.title,
type: 'bar',
barWidth: '16%',
barGap: '30%',
itemStyle: {
normal: {
color: color[i],
barBorderRadius: [50, 50, 0, 0]
}
},
data: m.data
};
return obj
})
var option = {
backgroundColor: '#fff',
tooltip: {
trigger: 'axis',
axisPointer: {
lineStyle: {
color: '#4379EE'
},
},
},
grid: {
top: '25px',
left: '40px',
right: '3%',
bottom: '40px',
// containLabel: true
},
legend: {
show: true,
orient: 'horizontal',
y:-2,
right:15,
itemWidth: 12,
itemHeight: 12,
itemGap: 24,
textStyle: {
color: 'rgba(43,48,52)',
fontSize:'14px'
}
},
xAxis: [{
type: 'category',
axisLine: {
show: false,
},
axisLabel: {
color: 'rgba(43,48,52, 0.4)',
margin: 20
},
axisTick: {
show: false
},
splitLine: {
show: false
},
boundaryGap: false,
data: params.xData
}],
yAxis: [{
minInterval:1,
type: 'value',
min: 0,
splitNumber: 4,
splitLine: {
show: true,
lineStyle: {
color: 'rgba(43,48,52, 0.1)',
}
},
axisLine: {
show: false,
},
axisLabel: {
color: 'rgba(43,48,52, 0.4)',
margin: 20,
},
axisTick: {
show: false,
},
}],
series: series
};
chart.setOption(option);
},
drawLine:function(chart,params){
let series = [];
params.yData.forEach(m=>{
series.push(
{
name:m.title,
type: 'line',
showAllSymbol: true,
symbol: 'circle',
symbolSize: 10,
lineStyle: {
normal: {
color: "#4379EE",
width:3
},
},
areaStyle: {
normal: {
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
{
offset: 0,
color: 'rgba(67,121,238,0.3)'
},
{
offset: 1,
color: 'rgba(67,121,238,0)'
}
], false),
}
},
data: m.data
}
)
})
let option = {
backgroundColor:'#fff',
tooltip: {
trigger: 'axis',
axisPointer: {
lineStyle: {
color: '#4379EE'
},
},
},
grid: {
top: '25px',
left: '40px',
right: '3%',
bottom: '40px',
// containLabel: true
},
xAxis: [{
type: 'category',
axisLine: {
show: false,
},
axisLabel: {
color: 'rgba(43,48,52, 0.4)',
margin: 20
},
axisTick: {
show: false
},
splitLine: {
show: false
},
boundaryGap: false,
data: params.xData
}],
yAxis: [{
minInterval:1,
type: 'value',
min: 0,
splitNumber: 4,
splitLine: {
show: true,
lineStyle: {
color: 'rgba(43,48,52, 0.1)',
}
},
axisLine: {
show: false,
},
axisLabel: {
color: 'rgba(43,48,52, 0.4)',
margin: 20,
},
axisTick: {
show: false,
},
}],
series: series
};
chart.setOption(option);
},
drawPie:function(chart,params){
let option = {
color: params.color,
backgroundColor: '#fff',
tooltip: {
trigger: 'item',
formatter: '{a}
{b} : {c}'
},
title: {
text: params.percentage,
textStyle: {
color: '#4379EE',
fontSize: 14,
align: 'center',
fontWeight: 'normal'
},
x: 'center',
y: 'center',
},
grid: {
top:20,
bottom: 20,
left: 0,
right: 0
},
legend: {
show: false,
},
series: [
// 主要展示层的
{
radius: ['55%', '90%'],
center: ['50%', '50%'],
type: 'pie',
label: {
show:false
},
name: params.title,
data: params.data,
},
// 边框的设置
{
radius: ['55%', '65%'],
center: ['50%', '50%'],
type: 'pie',
label: {
normal: {
show: false
},
emphasis: {
show: false
}
},
labelLine: {
normal: {
show: false
},
emphasis: {
show: false
}
},
animation: false,
tooltip: {
show: false
},
data: [{
value: 1,
itemStyle: {
color: "rgba(250,250,250,0.3)",
},
}],
}
]
};
chart.setOption(option);
},
drawGauge:function(chart,params){
let option = {
tooltip: {
formatter: "{a}
{b} : {c}%"
},
toolbox: {
feature: {
restore: {},
saveAsImage: {}
}
},
series: [
{
type: 'gauge',
axisLine: {
lineStyle: {
width: 28,
color: [
[0.3, '#67e0e3'],
[0.7, '#37a2da'],
[1, '#fd666d']
]
}
},
pointer: {
itemStyle: {
color: 'auto'
}
},
axisTick: {
distance: -28,
length: 8,
lineStyle: {
color: '#fff',
width: 2
}
},
splitLine: {
distance: -28,
length: 28,
lineStyle: {
color: '#fff',
width: 4
}
},
axisLabel: {
color: 'inherit',
distance: 40,
fontSize: 14
},
detail: {
valueAnimation: true,
formatter: '{value} %',
color: 'inherit',
textStyle: {
fontSize: 30,
align: 'center',
},
},
data: [
{
value: 70
}
]
}
]
};
chart.setOption(option,true);
},
drawPie0:function(chart,params){
const colorList = ['#F09595', '#A4EEDA','#F6C18B', '#86C1F4','#91A0FC','#59CB74', '#FBD444', '#7F6AAD', '#585247']
let option = {
title: {
text: '总工时',
textStyle: {
fontSize: 18,
color: '#000',
lineHeight: 20
},
textAlign: 'center',
left: '18.8%',
top: '45%'
},
tooltip: {
trigger: 'item',
},
legend: {
type: 'scroll',
orient: 'vertical',
right: '10%',
top: 'center',
itemGap: 30,
selectedMode: false,
icon: 'rect',
data: params.data.map((d) => d.name),
textStyle: {
color: '#3D3D3D',
fontSize:'12px',
rich: {
name: {
width: 60,
},
hours: {
width: 60,
},
penl: {
width: 60,
}
}
},
formatter(name) {
const item = params.data.find((d) => d.name === name);
return `{name|${item.name}}{hours|${item.value}小时}{penl|${item.penl}%}`
}
},
color: colorList,
series: [
{
name: '工时',
type: 'pie',
radius: [60, 90],
center: ['20%', '50%'],
label: {
show: false
},
labelLine: {
show: false
},
itemStyle: {
borderWidth: 1,
borderColor: '#fff'
},
data: params.data,
}
]
}
chart.setOption(option,true);
}
}
export {
iuCharts
}