/** 异常数据的折线图 */ function baseOption(title, xData) { return { title: { text: title, left: '1%', textStyle: { fontSize: 14 } }, tooltip: {}, toolbox: { // 工具栏 feature: { // 保存为图片 saveAsImage: {} } }, xAxis: { type: 'category', data: xData, name: '时间', axisLabel: { formatter: function (value) { return value.slice(11, -3) } } }, yAxis: { type: 'value', name: 'mg/m³' } } } function baseSeries(yData) { return { name: '颗粒物浓度', type: 'line', data: yData } } function baseMarkArea(area) { const _data = [] area.forEach((v) => { _data.push([{ xAxis: v[0] }, { xAxis: v[1] }]) }) return { itemStyle: { color: 'rgba(255, 173, 177, 0.4)' }, data: _data } } function baseVisualMap(area) { const _pieces = [] area.forEach((v, i) => { if (i == 0) { _pieces.push({ lt: v[0], color: 'green' }) } _pieces.push({ gte: v[0], lte: v[1], color: 'red' }) }) const lastOne = area[area.length - 1] _pieces.push({ gt: lastOne[1], color: 'green' }) return { show: false, dimension: 0, pieces: _pieces } } function baseMarkLine() { return { symbol: 'none', itemStyle: { // 基线公共样式 normal: { lineStyle: { type: 'dashed' }, label: { show: true, position: 'end', formatter: '{b}' } } }, data: [ { name: '超标', type: 'max', yAxis: 1, lineStyle: { color: 'red' } }, { name: '数据超低', type: 'min', yAxis: 0.02, lineStyle: { color: 'red' } } ] } } export default { /** * 获取各类异常的折线图配置项 * @param {*} param0 * @returns */ setExceptionChartOption2({ xData, yData, exceptionArea, exceptionName, exceptionType }) { const indexArea = [] exceptionArea.forEach((e) => { const i1 = xData.indexOf(e[0]) const i2 = xData.indexOf(e[1]) indexArea.push([i1, i2]) }) const option = baseOption(exceptionName, xData) const series = baseSeries(yData) series.markArea = baseMarkArea(exceptionArea) // 数据超低或超标 if (exceptionType == '1' || exceptionType == '2') { series.markLine = baseMarkLine() } const visualMap = baseVisualMap(indexArea) option.series = [series] option.visualMap = visualMap return option } }