import echarts from 'echarts'
import dayjs from 'dayjs'
function drawSafetyLine () {
const myChart = echarts.init(document.getElementById('safetyIndex'))
const yyyy = dayjs().format('YYYY') + '-'
const resDate = ['07-10', '07-11', '07-12', '07-13', '07-14', '07-15', '07-16']
const resValue = [35, 20, 10, 20, 40, 30, 10]
const safetyStandardValue = 20
myChart.setOption({
tooltip: {
trigger: 'axis',
formatter: '' + yyyy + '{b0}' +
'{a0}:{c0}
' +
'安全标准指数:' + safetyStandardValue + '', // 自定义tip格式
backgroundColor: 'rgba(73,177,231, 0.1)',
axisPointer: {
lineStyle: {
color: 'rgba(73,177,231, 0.5)',
type: 'dashed'
}
}
},
grid: {
left: '4%',
right: '10%',
bottom: '3%',
containLabel: true
},
xAxis: {
type: 'category',
boundaryGap: false,
data: resDate,
axisLine: {
show: false,
lineStyle: {
color: '#33FFF8'
}
},
axisTick: { // x轴刻度线
show: false
}
},
yAxis: {
type: 'value',
splitLine: {
lineStyle: {
type: 'dotted', // 设置网格线类型 dotted:虚线 solid:实线
color: 'rgb(73,177,231, 0.3)'
},
show: true
},
axisLine: {
show: false,
lineStyle: {
color: '#33FFF8'
}
},
axisTick: { // y轴刻度线
show: false
},
nameTextStyle: {
lineHeight: 20
}
},
series: [
{
name: '安全指数',
type: 'line',
data: resValue,
itemStyle: {
normal: {
lineStyle: {
color: 'rgb(233,209,74)',
width: 2 // 设置线条粗细
}
}
},
markLine: {
symbol: 'none', // 去掉标准线箭头
data: [
{
label: {
normal: {
position: 'end',
formatter: ''
}
},
name: '标准值',
yAxis: 20,
lineStyle: {
type: 'solid',
color: '#33FFF8',
width: 1
}
}
]
}
}
]
})
window.addEventListener('resize', () => {
myChart.resize()
})
}
export default {
drawSafetyLine
}