直接上代码
`function setOption(paramChart, title, chartType, xdata, ydata,yscale, dataFlag) {
let intervalVal = 0
if (dataFlag == 'staffAct') {intervalVal = 'auto'} else {intervalVal = 0}
const option = {color: ['#fff'],
title: {
text: '',
x: 'left',
y: 'top',
padding: 5,
textStyle: {
fontSize: 12,
color: '#fff'
},
},
grid: {
left: '3%',
right: '5%',
bottom: 15,
top: 15,
containLabel: true
},
xAxis: {
type: 'category',
data: xdata,
axisLine: {
lineStyle: {color: "#fff",}
},
axisLabel: {
interval: intervalVal,
formatter: function (value) {var reg = new RegExp("[\\u4E00-\\u9FFF]+", "g");
if (reg.test(value)){return (value.length > 4 ? (value.slice(0, 4) + "...") : value)
}else{return (value.length > 10 ? (value.slice(0, 10) + "...") : value)
}
},
rotate: -90,
fontSize:8,
}
},
yAxis: {
x: 'center',
type: 'value',
splitLine: {
lineStyle: {type: 'dashed'}
},
axisLine: {
lineStyle: {color: "#fff",}
},
axisLabel: {
fontSize: '12',
formatter: '{value}' + yscale
}
},
series: [{
type: chartType,
connectNulls: true,
// type: 'bar',
smooth: true,
barMaxWidth:15,
// label: {
// normal: {
// show: true,
// position: 'top'
// }
// },
label: {
normal: {
textStyle: {
fontSize: 12,
rich: {}}
}
},
data: ydata,
}, ]
};
paramChart.setOption(option)
}`
data:
`
ecStaffAct: {
lazyLoad: true
},
ecHeat: {lazyLoad: true},
`
调用:
`getStaffActData() {
let self = this
let param = {}
app.wxreq(app.globalData.DOMAIN_PATH + app.globalData.--, param, 'POST').then(res => {if (res.code == 0) {let datas = []
let chartKey = []
let chartVal = []
datas = res.data.visitTimeList
if (datas && datas.length > 0) {
datas.forEach(item => {chartKey.push(item.time.substring(item.time.length - 5))
chartVal.push(item.count)
});
} else {chartVal.push(0)
}
self.init_ecStaffAct(chartKey, chartVal)
}
}).then(res => {})
},`