//剪切原原始曲线 getSplitTend() { const timeCompare = [] this.trendOption.series[0].data.forEach(item => { timeCompare.push(item[0]) }) // console.log('timeCompare', timeCompare) const index = timeCompare.indexOf(this.splitData) if (index !== -1) { // 计算起始索引(不超过第一个元素) var startIndex = Math.max(0, index - 10) // 计算结束索引(不超过最后一个元素) var endIndex = Math.min( this.trendOption.series[0].data.length, index + 10 ) // 通过slice()函数截取指定范围的元素并存入新数组 var newArr = this.trendOption.series[0].data.slice(startIndex, endIndex) console.log('newArr', newArr) this.splitArrList = newArr this.trendOption.series[0].data = [] newArr.forEach(item => { this.trendOption.series[0].data.push(item) }) } else { console.log('未找到目标值') } }
标签:index,series,trendOption,timeCompare,数组,newArr,js,data,特定 From: https://www.cnblogs.com/zqlym/p/17983915