配置项如下
// See https://github.com/ecomfe/echarts-stat
echarts.registerTransform(ecStat.transform.regression);
myChart.resize({width:432,height:248})
const data_ori = [
['2020-11-23', 319],
['2020-11-24', 300],
['2020-11-25', 296],
['2020-11-26', 268],
['2020-11-27', 209],
['2020-11-28', 197],
['2020-11-29', 241],
['2020-11-30', 218],
['2020-12-01', 188],
['2020-12-02', 240],
['2020-12-03', 261],
['2020-12-04', 234],
['2020-12-05', 226],
['2020-12-06', 219],
['2020-12-07', 220],
['2020-12-08', 200],
['2020-12-09', 168],
['2020-12-10', 173],
['2020-12-11', 210],
['2020-12-12', 306],
['2020-12-13', 286],
['2020-12-14', 253],
['2020-12-15', 220],
['2020-12-16', 184],
['2020-12-17', 148],
['2020-12-18', 516],
['2020-12-19', 1984],
['2020-12-20', 1731],
['2020-12-21', 1250],
['2020-12-22', 1033],
['2020-12-23', 828],
['2020-12-24', 643],
['2020-12-25', 719],
['2020-12-26', 900],
['2020-12-27', 748],
['2020-12-28', 721],
['2020-12-29', 870],
['2020-12-30', 1200],
['2020-12-31', 1088],
['2021-01-01', 922],
['2021-01-02', 880],
['2021-01-03', 982],
['2021-01-04', 841],
['2021-01-05', 747],
['2021-01-06', 614],
['2021-01-07', 529],
['2021-01-08', 440],
['2021-01-09', 352],
['2021-01-10', 442],
['2021-01-11', 480],
['2021-01-12', 714],
['2021-01-13', 495],
['2021-01-14', 402],
['2021-01-15', 422],
['2021-01-16', 473],
['2021-01-17', 445],
['2021-01-18', 416],
['2021-01-19', 421],
['2021-01-20', 422],
['2021-01-21', 353],
['2021-01-22', 365],
['2021-01-23', 311],
['2021-01-24', 345],
['2021-01-25', 296],
['2021-01-26', 285],
['2021-01-27', 264],
['2021-01-28', 263],
['2021-01-29', 268],
['2021-01-30', 285],
['2021-01-31', 278],
['2021-02-01', 274],
['2021-02-02', 269],
['2021-02-03', 242],
['2021-02-04', 246],
['2021-02-05', 230],
['2021-02-06', 212],
['2021-02-07', 249],
['2021-02-08', 251],
['2021-02-09', 200],
['2021-02-10', 137],
['2021-02-11', 81],
['2021-02-12', 84],
['2021-02-13', 108],
['2021-02-14', 109],
['2021-02-15', 119],
['2021-02-16', 190],
['2021-02-17', 230],
['2021-02-18', 197],
['2021-02-19', 200],
['2021-02-20', 181],
['2021-02-21', 188],
['2021-02-22', 197],
['2021-02-23', 178],
['2021-02-24', 187],
['2021-02-25', 195],
['2021-02-26', 161],
['2021-02-27', 157],
['2021-02-28', 190],
['2021-03-01', 159],
['2021-03-02', 171],
['2021-03-03', 165],
['2021-03-04', 142],
['2021-03-05', 190],
['2021-03-06', 192],
['2021-03-07', 169],
['2021-03-08', 205],
['2021-03-09', 213],
['2021-03-10', 198],
['2021-03-11', 178],
['2021-03-12', 113],
['2021-03-13', 99],
['2021-03-14', 101],
['2021-03-15', 159],
['2021-03-16', 129],
['2021-03-17', 104],
['2021-03-18', 99],
['2021-03-19', 189],
['2021-03-20', 421],
['2021-03-21', 295],
['2021-03-22', 187],
['2021-03-23', 181],
['2021-03-24', 162],
['2021-03-25', 106],
['2021-03-26', 132],
['2021-03-27', 147],
['2021-03-28', 118],
['2021-03-29', 103],
['2021-03-30', 146],
['2021-03-31', 98],
['2021-04-01', 94],
['2021-04-02', 80],
['2021-04-03', 95],
['2021-04-04', 117],
['2021-04-05', 110],
['2021-04-06', 103],
['2021-04-07', 106],
['2021-04-08', 79],
['2021-04-09', 139],
['2021-04-10', 111],
['2021-04-11', 128],
['2021-04-12', 72],
['2021-04-13', 51],
['2021-04-14', 67],
['2021-04-15', 58],
['2021-04-16', 50],
['2021-04-17', 73],
['2021-04-18', 64],
['2021-04-19', 23],
['2021-04-20', 64],
['2021-04-21', 66],
['2021-04-22', 40],
['2021-04-23', 41],
['2021-04-24', 54],
['2021-04-25', 229],
['2021-04-26', 218],
['2021-04-27', 252],
['2021-04-28', 259],
['2021-04-29', 206],
['2021-04-30', 225],
['2021-05-01', 192],
['2021-05-02', 311],
['2021-05-03', 320],
['2021-05-04', 270],
['2021-05-05', 297],
['2021-05-06', 288],
['2021-05-07', 260],
['2021-05-08', 274],
['2021-05-09', 233],
['2021-05-10', 204],
['2021-05-11', 340],
['2021-05-12', 261],
['2021-05-13', 202],
['2021-05-14', 214],
['2021-05-15', 155],
['2021-05-16', 205],
['2021-05-17', 165],
['2021-05-18', 201],
['2021-05-19', 202],
['2021-05-20', 195],
['2021-05-21', 40]
];
const data_01 = data_ori.map((cur,Index) => ([Index+1,cur[1]]))
// console.log(data_01)
option = {
// backgroundColor:'#F2F2F2',
dataset: [{source:data_ori},{
source: data_01
}, {
fromDatasetIndex: 1,
transform: {
type: 'ecStat:regression',
}
}],
tooltip: {
trigger: 'axis',
axisPointer: {
type: 'cross'
},
formatter:params => {
console.log(params)
}
},
grid:{
left:40,
top:32,
right:32,
bottom:32
},
xAxis: [{
splitLine: {
show:false
},
type:'category',
axisLine:{onZero:false}
},{show:false}],
yAxis: {
splitLine: {
lineStyle: {
type: 'dashed'
}
},
// axisLabel:{
// formatter: val => val === 0? 0:`${val}%`
// },
axisLine:{
show:false,
},
axisTick:{show:false},
// min:80
},
series: [{
name: '趋势线',
datasetIndex:0,
xAxisIndex:0,
type: 'line',
symbolSize:0,
lineStyle:{
width:2
},
areaStyle:{
opacity:0.1,
origin: 'start',
color: {
type: 'linear',
x: 0,
y: 0,
x2: 0,
y2: 1,
colorStops: [
{ offset: 0.8, color: 'green' },
{ offset: 0.98, color: '#fff' },
// { offset: 1, color: '#3AD235' }
]
}
},
}, {
name: '回归线',
type: 'line',
datasetIndex: 2,
xAxisIndex:1,
symbolSize: 0.1,
symbol: 'circle',
lineStyle:{
color:"green",
width:1
},
label: { show: true, fontSize: 12 },
labelLayout: { dx: -20 },
encode: { label: 2, tooltip: 1 }
}]
};